home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OSK
/
EFFO
/
pd6.lzh
/
TST
/
blocks.tst
< prev
next >
Wrap
Text File
|
1989-12-21
|
762b
|
43 lines
.( Loading Blocks test...) cr
#include blocks.f83
locals blocks
.( 1: Define a code block for "nip") cr
block[ swap drop ]; constant nip
1 2 nip call . cr
.( 2: Define a code block in a colon definition and call it) cr
: foo block[ 5 + 3 * ]; call ;
6 foo . cr
.( 3: Make a colon definition return a code block depending on parameter) cr
: fie if block[ 5 + ]; else block[ 8 + ]; then ;
5 true fie call . cr
.( 4: Show that blocks can return blocks as values) cr
5 false block[ if block[ 5 + ]; else block[ 8 + ]; then ]; call call . cr
.( 5: Define a generalized factorial function block) cr
block[ { x y z } x 0> if x 1- y z y call x * else z call then ]; constant fum
: fac ( n -- n! ) fum block[ 1 ]; fum call ;
5 fac . cr
forth only