From f28db7decf3330379f3f4ab190a9bc01deb50b91 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 2 Jan 2015 01:36:06 -0400 Subject: Pattern matching compiler now generates optimized code. --- test2.lang | 53 +++++++++++++++++++++++------------------------------ 1 file changed, 23 insertions(+), 30 deletions(-) (limited to 'test2.lang') diff --git a/test2.lang b/test2.lang index 73c6d206e..c697ae3c8 100644 --- a/test2.lang +++ b/test2.lang @@ -10,35 +10,13 @@ (defclass Variant [[java.lang.String tag] [java.lang.Object value]]) -#( (def (++ xs ys) - (case xs - #Nil - ys - - (#Cons x xs*) - (#Cons x (++ xs* ys)))) )# - -#( (def (main args) - (if true - (case (#Pair "Pattern" "Matching") - (#Pair first second) - (do (:: (:: System out) (println first)) - (:: (:: System out) (println second)))) - (:: (:: System out) (println "FALSE")))) )# +(def (++ xs ys) + (case xs + #Nil + ys -(def (main args) - (if true - (let xs+ys (#Cons "Pattern" (#Cons "Matching" #Nil)) - (case xs+ys - (#Cons "Pattern" (#Cons second #Nil)) - (do (:: (:: System out) (println "Branch #1")) - (:: (:: System out) (println second))) - - (#Cons first (#Cons second #Nil)) - (do (:: (:: System out) (println "Branch #2")) - (:: (:: System out) (println first)) - (:: (:: System out) (println second))))) - (:: (:: System out) (println "FALSE")))) + (#Cons x xs*) + (#Cons x (++ xs* ys)))) #( (def (template elems) (case elems @@ -55,9 +33,24 @@ _ (#Cons head (template tail))) - )) + )) )# + +#( )# + +(def (main args) + (if true + (case (++ (#Cons "Pattern" #Nil) (#Cons "Matching" #Nil)) + (#Cons "Pattern" (#Cons second #Nil)) + (do (:: (:: System out) (println "Branch #1")) + (:: (:: System out) (println second))) + + (#Cons first (#Cons second #Nil)) + (do (:: (:: System out) (println "Branch #2")) + (:: (:: System out) (println first)) + (:: (:: System out) (println second)))) + (:: (:: System out) (println "FALSE")))) - (defmacro (' form) +#( (defmacro (' form) (case form (#Cons form* #Nil) (case form* -- cgit v1.2.3