Advertisement
konalisp

stuff.fs

May 14th, 2014
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.64 KB | None | 0 0
  1. : doubledip ( -- n )
  2.     dup dup +
  3. ;
  4.  
  5. : fact1 ( n -- n! ) recursive \ recursive declaration
  6.     dup 1 > if dup 1- fact1 * then
  7. ;
  8.  
  9. : fact2 ( n -- n! ) \ recurse instead of calling function
  10.     dup 1 > if dup 1- recurse * then
  11. ;
  12.  
  13. variable thing1 \ make a variable
  14. 10 thing1 ! \ put 10 on the stack, and ! stores it in "thing1"
  15.  
  16. 0 value thing2 \ make a variable called "thing2", must have an actual value before "value"
  17. 12 to thing2 \ "to" can put stuff in "thing2"
  18.  
  19. 4 doubledip
  20. swap drop
  21.  
  22. thing1 @ fact2 \ @ fetches from "thing1" and puts it on the stack
  23. thing2 fact1 \ "thing2" can fetch it's own value if it's defined with "value"
  24.  
  25. .s bye
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement