home *** CD-ROM | disk | FTP | other *** search
- \ Forth source file
- \ Copyright Mads Meisner-Jensen, 6 Apr 1993
- \ Miscellaneous examples
-
- \ The following four words was found in comp.lang.forth on UseNet
- \ They were originally made by rob@idacom.hp.com (Rob Chapman)
- \ They are merely meant for entertainment, nothing serious!
-
- \ This word "lifts" the bottom item on the stack to the top of the stack.
- : LIFTUP ( w1 w2 w3 .. wn -- w2 w3 .. wn w1 )
- DEPTH 1 > IF >R RECURSE R> SWAP THEN ;
-
- \ This word does the exact opposite of LIFTUP.
- : LIFTDOWN ( w1 w2 w3 .. wn-1 wn -- wn w1 w2 w3 .. wn-1 )
- DEPTH 1 > IF SWAP >R RECURSE R> THEN ;
-
- \ Reverse the order of items on the stack.
- : REV1 ( w1 w2 w3 .. wn-1 wn -- wn wn-1 .. w3 w2 w1 )
- DEPTH 1 > IF >R RECURSE R> LIFTDOWN THEN ;
-
- \ This word does exactly the same as REV1, but does it another way.
- : REV2 ( w1 w2 w3 .. wn-1 wn -- wn wn-1 .. w3 w2 w1 )
- DEPTH 1 > IF LIFTUP >R RECURSE R> THEN ;
-