From a49c59d996a8503ee07835ab9dccd26bd1a8c9a4 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Mon, 12 Jan 2015 01:24:16 -0400 Subject: - 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. --- test2.lux | 53 ++++++++++++++++++++++++++++++++++++++++++----------- 1 file changed, 42 insertions(+), 11 deletions(-) (limited to 'test2.lux') diff --git a/test2.lux b/test2.lux index 9cea62d8a..a75243191 100644 --- a/test2.lux +++ b/test2.lux @@ -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)) -- cgit v1.2.3