Re: Star Trek by Krishna Myneni
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: Star Trek by Krishna Myneni         

Group: comp.lang.forth · Group Profile
Author: The Beez'
Date: Sep 19, 2008 08:01

For those who want to debug along, this is the underlying code:

---8<---
1 cells constant INTEGER
: ?allot here swap allot ;

: cell- ( a1 -- a2 | backup 1 cell)
[ 1 cells ] literal - ;

: matrix ( n m size -- )
create >r 2dup * r@ * 2 cells + ?allot
2dup ! cell+ r> swap ! 2drop does> [ 2 cells ] literal + ;

: }} ( addr i j -- addr[i][j] | fetch 2-D array address)
>r >r dup cell- cell- 2@ r> * r> + * + ;

9 9 INTEGER matrix g{{ \ the galaxy
4 4 INTEGER matrix k{{ \ Klingon data
9 9 INTEGER matrix z{{ \ cumulative record of galaxy

: array ( n cell_size -- | -- addr )
create 2dup swap 1+ * ?allot ! drop does> cell+ ;

: } ( addr n -- addr[n] | fetch 1-D array address)
over cell- @ * swap + ;

3 INTEGER array n{
---8<---

Hans Bezemer
no comments
diggit! del.icio.us! reddit!