1234567891011121314151617181920212223 |
- : square ( n -- n² ) dup * ;
- 5 square .
- 7 square .
- : cube ( n -- n³ ) dup square * ;
- 6 cube .
- 2 cube .
- : n^4 ( n -- n^4 ) square square ;
- 3 n^4 .
- 2 n^4 .
- \ 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 / ;
|