aboutsummaryrefslogtreecommitdiff
path: root/test2.lang
diff options
context:
space:
mode:
authorEduardo Julian2015-01-03 01:48:08 -0400
committerEduardo Julian2015-01-03 01:48:08 -0400
commit648110a554a13e1caaf846a60c85cccadcda6e0d (patch)
treeb81414d285dd3d2fdf93f4f2059235ed4a184baf /test2.lang
parent7ae54659d09aef5ced3544c650c80d7580a0dbb7 (diff)
The language now supports macros.
Diffstat (limited to 'test2.lang')
-rw-r--r--test2.lang129
1 files changed, 73 insertions, 56 deletions
diff --git a/test2.lang b/test2.lang
index b3756a6e8..243ab902a 100644
--- a/test2.lang
+++ b/test2.lang
@@ -1,5 +1,5 @@
(import java.lang.System)
-(require "./another" as another)
+## (require "./another" as another)
(definterface Function
(: apply (-> [java.lang.Object] java.lang.Object)))
@@ -25,67 +25,84 @@
(#Cons head tail)
(case head
- (#Cons (#Symbol "~") (#Cons unquoted #Nil))
+ (#Form (#Cons (#Ident "~") (#Cons unquoted #Nil)))
(#Cons unquoted (template tail))
- (#Cons (#Symbol "~@") (#Cons spliced #Nil))
- (#Cons (#Symbol "++") (#Cons spliced (template tail)))
+ (#Form (#Cons (#Ident "~@") (#Cons spliced #Nil)))
+ (#Cons (#Ident "++") (#Cons spliced (template tail)))
_
(#Cons head (template tail))
- )
- ))
+ )))
+
+(defmacro (' form)
+ (case form
+ (#Cons form* #Nil)
+ (case form*
+ (#Form elems)
+ (#Quote (#Form (template elems)))
+
+ _
+ (#Quote form*)
+ )))
(def (main args)
- (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)))
+ (case (' ((~ "TROLOLOL")))
+ (#Form (#Cons (#Text text) #Nil))
+ (:: (:: System out) (println text))
))
-#( (defmacro (' form)
- (case form
- (#Cons form* #Nil)
- (case form*
- (#Form elems)
- (#Quote (#Form (template elems)))
-
- _
- (#Quote form*))
- ))
-
- (defmacro (::+ pieces)
- (case pieces
- (#Cons init #Nil)
- init
-
- (#Cons init (#Cons access others))
- (' (::+ (:: (~ init) (~ access)) (~@ others)))
- ))
-
- (def (main args)
- (if true
- (let f (lambda [x] (lambda [y] (x y)))
- (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"))))
- )#
+#(
+ (defmacro (::+ pieces)
+ (case pieces
+ (#Cons init #Nil)
+ init
+
+ (#Cons init (#Cons access others))
+ (' (::+ (:: (~ init) (~ access)) (~@ others)))
+ ))
+
+ (def (main args)
+ (if true
+ (let f (lambda [x] (lambda [y] (x y)))
+ (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"))))
+
+ (def (main args)
+ (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)))
+ ))
+
+ (def (main args)
+ (case (' "YOLO")
+ (#Text text)
+ (:: (:: System out) (println text))))
+
+ (def (main args)
+ (case (' ((~ "TROLOLOL")))
+ (#Form (#Cons (#Text text) #Nil))
+ (:: (:: System out) (println text))
+ ))
+ )#