10-local-variables.fth 675 B

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