home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / a293_1 / !AForth_Examples_Fun < prev    next >
Encoding:
Text File  |  1999-04-27  |  914 b   |  24 lines

  1. \ Forth source file
  2. \ Copyright Mads Meisner-Jensen, 6 Apr 1993
  3. \ Miscellaneous examples
  4.  
  5. \ The following four words was found in comp.lang.forth on UseNet
  6. \ They were originally made by rob@idacom.hp.com (Rob Chapman)
  7. \ They are merely meant for entertainment, nothing serious!
  8.  
  9. \ This word "lifts" the bottom item on the stack to the top of the stack.
  10. : LIFTUP  ( w1 w2 w3 .. wn -- w2 w3 .. wn w1 )
  11.   DEPTH 1 > IF  >R  RECURSE  R> SWAP  THEN ;
  12.  
  13. \ This word does the exact opposite of LIFTUP.
  14. : LIFTDOWN  ( w1 w2 w3 .. wn-1 wn -- wn w1 w2 w3 .. wn-1 )
  15.   DEPTH 1 > IF  SWAP >R RECURSE  R>  THEN ;
  16.  
  17. \ Reverse the order of items on the stack.
  18. : REV1  ( w1 w2 w3 .. wn-1 wn -- wn wn-1 .. w3 w2 w1 )
  19.   DEPTH 1 > IF  >R RECURSE  R> LIFTDOWN  THEN ;
  20.  
  21. \ This word does exactly the same as REV1, but does it another way.
  22. : REV2  ( w1 w2 w3 .. wn-1 wn -- wn wn-1 .. w3 w2 w1 )
  23.   DEPTH 1 > IF  LIFTUP >R RECURSE  R>  THEN ;
  24.