From 7ae54659d09aef5ced3544c650c80d7580a0dbb7 Mon Sep 17 00:00:00 2001 From: Eduardo Julian Date: Fri, 2 Jan 2015 03:29:32 -0400 Subject: Fixed a bug in pattern-matching when expanding sequential tests. --- test2.lang | 69 ++++++++++++++++++++++++++++++++++++-------------------------- 1 file changed, 40 insertions(+), 29 deletions(-) (limited to 'test2.lang') diff --git a/test2.lang b/test2.lang index c697ae3c8..b3756a6e8 100644 --- a/test2.lang +++ b/test2.lang @@ -18,37 +18,36 @@ (#Cons x xs*) (#Cons x (++ xs* ys)))) -#( (def (template elems) - (case elems - #Nil - elems - - (#Cons head tail) - (case head - (#Cons (#Symbol "~") (#Cons unquoted #Nil)) - (#Cons unquoted (template tail)) +(def (template elems) + (case elems + #Nil + elems - (#Cons (#Symbol "~@") (#Cons spliced #Nil)) - (#Cons (#Symbol "++") (#Cons spliced (template tail))) + (#Cons head tail) + (case head + (#Cons (#Symbol "~") (#Cons unquoted #Nil)) + (#Cons unquoted (template tail)) - _ - (#Cons head (template tail))) - )) )# + (#Cons (#Symbol "~@") (#Cons spliced #Nil)) + (#Cons (#Symbol "++") (#Cons spliced (template tail))) -#( )# + _ + (#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")))) + (case (template (#Cons (#Cons (#Symbol "~@") (#Cons (#Symbol "Pattern") #Nil)) #Nil) + ## (#Cons (#Cons (#Symbol "~") (#Cons (#Symbol "Pattern") #Nil)) #Nil) + ) + (#Cons word #Nil) + (do (:: (:: System out) (println "Branch #1")) + (:: (:: System out) (println word))) + + (#Cons (#Symbol op) spliced) + (do (:: (:: System out) (println "Branch #2")) + (:: (:: System out) (println op))) + )) #( (defmacro (' form) (case form @@ -73,8 +72,20 @@ (def (main args) (if true (let f (lambda [x] (lambda [y] (x y))) - (let g (lambda [x] const) - (::+ System out (println (f g "WE'VE GOT CLOSURES!"))) - ## (:: (:: System out) (println (f g "WE'VE GOT CLOSURES!"))))) + (let g (lambda [x] x) + (::+ System out (println (f g "WE'VE GOT CLOSURES!"))))) + (:: (:: System out) (println "FALSE")))) + + (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")))) )# -- cgit v1.2.3