123456789101112131415161718192021 |
- \ Assignment: Write colon definitions for nip, tuck, negate,
- \ and /mod in terms of other Forth words, and check if they
- \ work (hint: test your tests on the originals first). Don't
- \ let the `redefined'-Messages spook you, they are just
- \ warnings.
- : nip ( a b c -- a b ) swap drop ;
- : tuck ( a b c -- a c b c ) swap over ;
- : negate ( n -- -n ) -1 * ;
- : /mod ( a b -- a modulo b, a div b) 2dup mod rot rot / ;
- \ Assignment: Rewrite your definitions until now using locals.
- : nip ( a b c -- a c ) { a b c } a b ;
- : tuck ( a b c -- a c b c ) { a b c } a c b c ;
- : negate ( n -- -n ) { n } n -1 * ;
- : /mod ( a b -- a modulo b, a div b)
- { a b }
- a b a b
- mod rot rot / ;
|