diff options
author | Eduardo Julian | 2015-01-12 01:24:16 -0400 |
---|---|---|
committer | Eduardo Julian | 2015-01-12 01:24:16 -0400 |
commit | a49c59d996a8503ee07835ab9dccd26bd1a8c9a4 (patch) | |
tree | eb32ec2f167850eef548289e9ac3f0ceb598f8d4 /test2.lux | |
parent | 7f076e6ca1a107b6b0ce54784e9b9eb2ae715771 (diff) |
- Greatly simplified the AST and made it more macro-friendly.
- Modified the implementation of ' (quote) to reflect this.
- There is no longer a #Quote syntax token.
Diffstat (limited to 'test2.lux')
-rw-r--r-- | test2.lux | 53 |
1 files changed, 42 insertions, 11 deletions
@@ -96,15 +96,46 @@ (#Cons head (template tail)) ))) +(def (map f xs) + (case xs + #Nil + #Nil + + (#Cons x xs*) + (#Cons (f x) (map f xs*)))) + +(def (convert-list f xs) + (case xs + #Nil + (#Tag "Nil") + + (#Cons x xs*) + (#Form (#Cons (#Tag "Cons") (#Cons (f x) (#Cons (convert-list f xs*) #Nil)))))) + +(def (convert token) + (case token + (#Tag tag) + (#Form (#Cons (#Tag "Tag") (#Cons (#Text tag) #Nil))) + + (#Text text) + (#Form (#Cons (#Tag "Text") (#Cons (#Text text) #Nil))) + + (#Ident ident) + (#Form (#Cons (#Tag "Ident") (#Cons (#Text ident) #Nil))) + + (#Form elems) + (#Form (#Cons (#Tag "Form") (#Cons (convert-list convert elems) #Nil))) + )) + (defmacro (' form) (case form (#Cons form* #Nil) (case form* (#Form elems) - (#Quote (#Form (template elems))) + (convert (#Form (template elems))) _ - (#Quote form*) + (convert form) ))) ## Utils @@ -162,22 +193,22 @@ (jvm/invokevirtual Object "equals" [Object] x [y])) -#( (def (as-pairs list) - (case list - (#Cons x (#Cons y list*)) - (#Cons [x y] (as-pairs list*)) +(def (as-pairs list) + (case list + (#Cons x (#Cons y list*)) + (#Cons [x y] (as-pairs list*)) - _ - #Nil)) + _ + #Nil)) - (defmacro (exec tokens) +#( (defmacro (exec tokens) (case tokens (#Cons (#Tuple steps) (#Cons return #Nil)) - (if (= 0 (mod (length steps) 2)) + (if (= 0 (rem (length steps) 2)) (fold (lambda [inner pair] (case pair [label computation] - (` (bind (~ computation) + (' (bind (~ computation) (lambda [(~ label)] (~ inner)))))) return (as-pairs steps)) |