diff options
author | Eduardo Julian | 2015-01-02 01:36:06 -0400 |
---|---|---|
committer | Eduardo Julian | 2015-01-02 01:36:06 -0400 |
commit | f28db7decf3330379f3f4ab190a9bc01deb50b91 (patch) | |
tree | 8bb62dbe50a8751135f9d190a829ae3888365985 /test2.lang | |
parent | 6eebd55535254e82230ce0ad11f7eb8b7907a9ca (diff) |
Pattern matching compiler now generates optimized code.
Diffstat (limited to '')
-rw-r--r-- | test2.lang | 53 |
1 files changed, 23 insertions, 30 deletions
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* |