aboutsummaryrefslogtreecommitdiff
path: root/test2.lang
blob: b3756a6e8940bd468e7d55952d9146bd63ebd68f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
(import java.lang.System)
(require "./another" as another)

(definterface Function
  (: apply (-> [java.lang.Object] java.lang.Object)))

(defclass Tuple0 [])
(defclass Tuple1 [[java.lang.Object _0]])
(defclass Tuple2 [[java.lang.Object _0] [java.lang.Object _1]])

(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 (template elems)
  (case elems
    #Nil
    elems

    (#Cons head tail)
    (case head
      (#Cons (#Symbol "~") (#Cons unquoted #Nil))
      (#Cons unquoted (template tail))

      (#Cons (#Symbol "~@") (#Cons spliced #Nil))
      (#Cons (#Symbol "++") (#Cons spliced (template tail)))

      _
      (#Cons head (template tail))
      )
    ))

(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)))
    ))

#( (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"))))
   )#