30 lines
745 B
Forth
30 lines
745 B
Forth
( Problems, page 269 )
|
|
( This is problem 6, chapter 2 )
|
|
: homicide 20 + ;
|
|
: arson 10 + ;
|
|
: bookmaking 2 + ;
|
|
: tax-evasion 5 + ;
|
|
: convicted-of 0 ;
|
|
: will-serve . ." years" ;
|
|
|
|
: counts ( n -- n )
|
|
0 ' execute * + ;
|
|
|
|
here
|
|
|
|
pad here - .
|
|
\ => 176
|
|
|
|
( The difference between "date ." and "' date ." and the same for the base
|
|
example is that the latter will print the address to the code that will push
|
|
the value onto the stack, while the former will push the address to the
|
|
variable to the stack. I think? )
|
|
|
|
: greet ." Hello!" ;
|
|
: count cr 10 0 do i . space loop ;
|
|
: stars cr 10 0 do 42 emit loop ;
|
|
: do-nothing ;
|
|
create exec-array ' greet , ' count , ' stars , ' do-nothing ,
|
|
: do-something ( i -- )
|
|
1- 8 * exec-array + @ execute ;
|