Advertisement
Guest User

Untitled

a guest
Nov 27th, 2015
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. : nil? nil = ;
  2. : not-nil? nil? invert ;
  3. : cons ( tail, head -- consc ) , , HERE 2 cells - ;
  4. : head ( consc -- e ) @ ;
  5. : tail ( consc -- e ) 1 cells + @ ;
  6. : even? ( n -- bool ) 2 mod 0 = ;
  7. : odd? ( n -- bool ) even? invert ;
  8.  
  9. nil 1 cons head 1 = .
  10. nil 1 cons tail nil = .
  11. nil 2 cons 1 cons head 1 = .
  12. nil 2 cons 1 cons tail head 2 = .
  13. nil 2 cons 1 cons tail tail nil = .
  14. nil 3 cons 2 cons 1 cons head 1 = .
  15.  
  16. nil 3 cons 2 cons 1 cons CONSTANT alist
  17.  
  18. alist head 1 = .
  19. alist tail head 2 = .
  20.  
  21. 2 even? .
  22. 3 odd? .
  23.  
  24. : filter ( pred, consc -- consc ) recursive
  25. 2dup not-nil? if
  26. over dup head rot execute if
  27. tail swap head cons filter
  28. else
  29. drop tail filter
  30. then
  31. else
  32. drop nip
  33. then ;
  34.  
  35. ' odd? alist filter
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement