aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/lux.lux108
1 files changed, 62 insertions, 46 deletions
diff --git a/source/lux.lux b/source/lux.lux
index 4a53e088b..3e29a50c9 100644
--- a/source/lux.lux
+++ b/source/lux.lux
@@ -67,12 +67,11 @@
[java.lang.Object _7] [java.lang.Object _8]])
## Base functions & macros
-(annotate lambda Macro)
(def' lambda
(lambda' _ tokens
(lambda' _ state
(let' output (case' tokens
- (#Cons self (#Cons (#Tuple (#Cons arg args')) (#Cons body #Nil)))
+ (#Cons (#Form (#Cons self (#Cons arg args'))) (#Cons body #Nil))
(#Form (#Cons (#Ident "lambda'")
(#Cons self
(#Cons arg
@@ -82,44 +81,30 @@
_
(#Form (#Cons (#Ident "lux;lambda")
- (#Cons (#Tuple args')
- (#Cons body #Nil)))))
- #Nil)))))
-
- (#Cons (#Tuple (#Cons arg args')) (#Cons body #Nil))
- (#Form (#Cons (#Ident "lambda'")
- (#Cons (#Ident "_")
- (#Cons arg
- (#Cons (case args'
- #Nil
- body
-
- _
- (#Form (#Cons (#Ident "lux;lambda")
- (#Cons (#Tuple args')
+ (#Cons (#Form (#Cons (#Ident "_") args'))
(#Cons body #Nil)))))
#Nil))))))
[(#Cons output #Nil) state]))))
+(declare-macro lambda)
-(annotate def Macro)
(def' def
- (lambda [tokens state]
+ (lambda (_ tokens state)
(let' output (case' tokens
- (#Cons (#Ident name) (#Cons body #Nil))
- (#Form (#Cons (#Ident "def'")
- (#Cons (#Ident name)
- (#Cons body #Nil))))
-
- (#Cons (#Form (#Cons (#Ident name) args))
- (#Cons body #Nil))
- (#Form (#Cons (#Ident "def'")
- (#Cons (#Ident name)
- (#Cons (#Form (#Cons (#Ident "lux:lambda")
- (#Cons (#Ident name)
- (#Cons (#Tuple args)
- (#Cons body #Nil)))))
- #Nil)))))
+ (#Cons (#Ident name) (#Cons body #Nil))
+ (#Form (#Cons (#Ident "def'")
+ (#Cons (#Ident name)
+ (#Cons body #Nil))))
+
+ (#Cons (#Form (#Cons (#Ident name) args))
+ (#Cons body #Nil))
+ (#Form (#Cons (#Ident "def'")
+ (#Cons (#Ident name)
+ (#Cons (#Form (#Cons (#Ident "lux:lambda")
+ (#Cons (#Form (#Cons (#Ident name) args))
+ (#Cons body #Nil))))
+ #Nil)))))
[(#Cons output #Nil) state])))
+(declare-macro def)
(def (+ x y)
(jvm;iadd x y))
@@ -138,15 +123,15 @@
(def (fold f init xs)
(do (print "fold ") (print init) (print " ") (println xs)
(case' xs
- #Nil
- init
-
- (#Cons x xs')
- (let' init' (f init x)
- (do (print "init': ") (println init')
- (fold f init' xs')))
- #((fold f (f init x) xs'))#
- )))
+ #Nil
+ init
+
+ (#Cons x xs')
+ (let' init' (f init x)
+ (do (print "init': ") (println init')
+ (fold f init' xs')))
+ #((fold f (f init x) xs'))#
+ )))
(def (reverse list)
(do (print "reverse ") (println list)
@@ -158,7 +143,6 @@
(do (print "!reversed ") (println reversed)
reversed))))
-(annotate list Macro)
(def (list xs state)
(let' xs' (reverse xs)
(let' output (fold (lambda [tail head]
@@ -171,8 +155,8 @@
xs'))
(do (print "output: ") (println output)
[(#Cons output #Nil) state]))))
+(declare-macro list)
-(annotate list+ Macro)
(def (list+ xs state)
(case' (reverse xs)
#Nil
@@ -185,6 +169,7 @@
last
init')
[(#Cons output #Nil) state])))
+(declare-macro list+)
(def (->pairs xs)
(case' xs
@@ -194,7 +179,6 @@
_
#Nil))
-(annotate let Macro)
(def (let tokens state)
(case' tokens
(#Cons (#Tuple bindings) (#Cons body #Nil))
@@ -205,6 +189,7 @@
body
(reverse (->pairs bindings)))
[(list output) state])))
+(declare-macro let)
(def (++-list xs ys)
(case' xs
@@ -274,11 +259,11 @@ unquoted
(jvm;invokevirtual java.io.PrintStream "println" [Object]
(jvm;getstatic System out) [x]))
-(annotate ' Macro)
(def (' form)
(case form
(#Cons token #Nil)
(untemplate token)))
+(declare-macro ')
(def (+ x y)
(jvm;iadd x y))
@@ -853,3 +838,34 @@ n
(lambda [chan]
(chan value)))
)#
+
+## (defsig (Equal a)
+## (: = (-> a a Bool)))
+
+## (: not= (All [a] (-> (Equal a) a a Bool)))
+## (def (not= &Equal
+## x x)
+## (not (:: &Equal (= x x))))
+
+## (defstruct Int
+## []
+## (Equal Int)
+
+## (def (= x y)
+## (zero? (- x y))))
+
+## (defsig (Show a)
+## (: show (-> a Text)))
+
+## (defstruct (ListShow x)
+## [&show (Show a)]
+## (Show (List a))
+
+## (def (show xs)
+## (<> "(" (interpose ", " (map (:: &show show) xs)) ")")))
+
+## (def ListShow
+## (: (lambda [&show]
+## {#show (lambda show [xs]
+## (<> "(" (interpose ", " (map (:: &show show) xs)) ")"))})
+## (-> (Show a) (Show (List a)))))