Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2017
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. Red [
  2. Title: "Lispy reader macros"
  3. Dedication: "to the spirit that lives in the computer"
  4. Author: 9214
  5. Date: 24-Aug-2017
  6. Usage: {
  7. o plug in REPL with do %<filename>.red or simply copypaste;
  8. o have fun!
  9. }
  10.  
  11. Tip: "use backtick to quote paren! (i.e. s-expressions)"
  12. Example: [
  13. SICP ex. 2.25
  14.  
  15. cadaddr `(1 3 (5 7) 9)
  16. caar `((7))
  17. cadadadadadadr `(1 (2 (3 (4 (5 (6 7))))))
  18. ]
  19. ]
  20.  
  21. system/lexer/pre-load: function [src part][
  22. new: object [
  23. _: {}
  24. rst: does [clear _]
  25. fmt: func ['word][form reduce [space :word space]]
  26. add: func ['word][append _ fmt :word]
  27.  
  28. -a-: does [add first]
  29. -d-: does [add next]
  30. ]
  31.  
  32. c~r: [#"c" some [#"a" (-a-) | #"d" (-d-)] #"r"]
  33. tweak: quote (s: change/part s _ e rst)
  34. lisp: compose/only [s: (c~r) e: (tweak) :s | skip]
  35. rule: reduce ['any lisp]
  36.  
  37. set '` :quote
  38. parse src bind rule new
  39. ]
  40.  
  41. 'ok
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement