aboutsummaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
Diffstat (limited to 'source')
-rw-r--r--source/lux.lux134
1 files changed, 70 insertions, 64 deletions
diff --git a/source/lux.lux b/source/lux.lux
index 8aefa309a..24b5cb837 100644
--- a/source/lux.lux
+++ b/source/lux.lux
@@ -5,48 +5,48 @@
## Base functions & macros
(def' let'
(lambda' _ tokens
- (lambda' _ state
- (case' tokens
- (#Cons [lhs (#Cons [rhs (#Cons [body #Nil])])])
- [(#Cons [(#Form (#Cons [(#Ident "case'") (#Cons [rhs (#Cons [lhs (#Cons [body #Nil])])])]))
- #Nil])
- state])
- )))
+ (lambda' _ state
+ (case' tokens
+ (#Cons [lhs (#Cons [rhs (#Cons [body #Nil])])])
+ (#Ok [state
+ (#Cons [(#Form (#Cons [(#Ident "case'") (#Cons [rhs (#Cons [lhs (#Cons [body #Nil])])])]))
+ #Nil])]))
+ )))
(declare-macro let')
(def' lambda
(lambda' _ tokens
- (lambda' _ state
- (let' output (case' tokens
- (#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 [body #Nil])])])))
- #Nil])])])]))
-
- (#Cons [(#Ident self) (#Cons [(#Tuple (#Cons [arg args'])) (#Cons [body #Nil])])])
- (#Form (#Cons [(#Ident "lambda'")
- (#Cons [(#Ident self)
- (#Cons [arg
- (#Cons [(case' args'
- #Nil
- body
-
- _
- (#Form (#Cons [(#Ident "lux;lambda")
- (#Cons [(#Tuple args')
- (#Cons [body #Nil])])])))
- #Nil])])])])))
- [(#Cons [output #Nil]) state])
- )))
+ (lambda' _ state
+ (let' output (case' tokens
+ (#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 [body #Nil])])])))
+ #Nil])])])]))
+
+ (#Cons [(#Ident self) (#Cons [(#Tuple (#Cons [arg args'])) (#Cons [body #Nil])])])
+ (#Form (#Cons [(#Ident "lambda'")
+ (#Cons [(#Ident self)
+ (#Cons [arg
+ (#Cons [(case' args'
+ #Nil
+ body
+
+ _
+ (#Form (#Cons [(#Ident "lux;lambda")
+ (#Cons [(#Tuple args')
+ (#Cons [body #Nil])])])))
+ #Nil])])])])))
+ (#Ok [state (#Cons [output #Nil])]))
+ )))
(declare-macro lambda)
(def' def
@@ -64,7 +64,7 @@
(#Cons [(#Tuple args)
(#Cons [body #Nil])])])]))
#Nil])])])))
- [(#Cons [output #Nil]) state])))
+ (#Ok [state (#Cons [output #Nil])]))))
(declare-macro def)
(def (defmacro tokens state)
@@ -80,11 +80,11 @@
(#Cons [body
#Nil])])]))])
(let' declaration (#Form (#Cons [(#Ident "declare-macro") (#Cons [(#Ident fn-name) #Nil])]))
- [(#Cons [fn-def (#Cons [declaration #Nil])]) state])))
+ (#Ok [state (#Cons [fn-def (#Cons [declaration #Nil])])]))))
(declare-macro defmacro)
(defmacro (comment tokens state)
- [#Nil state])
+ (#Ok [state #Nil]))
(def (int+ x y)
(jvm-iadd x y))
@@ -121,9 +121,8 @@
(#Cons [(#Tuple (#Cons [head (#Cons [tail #Nil])]))
#Nil])])))
(#Tag "Nil")
- xs'
- )
- [(#Cons [output #Nil]) state])))
+ xs')
+ (#Ok [state (#Cons [output #Nil])]))))
(defmacro (list+ xs state)
(case' (reverse xs)
@@ -135,7 +134,7 @@
(#Form (list (#Tag "Cons") (#Tuple (list head tail)))))
last
init')
- [(#Cons [output #Nil]) state])))
+ (#Ok [state (#Cons [output #Nil])]))))
(def (as-pairs xs)
(case' xs
@@ -145,16 +144,16 @@
_
#Nil))
-## (defmacro (let tokens state)
-## (case' tokens
-## (#Cons [(#Tuple bindings) (#Cons [body #Nil])])
-## (let' output (fold (lambda [body binding]
-## (case' binding
-## [label value]
-## (#Form (list (#Ident "lux;let'") label value body))))
-## body
-## (reverse (as-pairs bindings)))
-## [(list output) state])))
+(defmacro (let tokens state)
+ (case' tokens
+ (#Cons [(#Tuple bindings) (#Cons [body #Nil])])
+ (let' output (fold (lambda [body binding]
+ (case' binding
+ [label value]
+ (#Form (list (#Ident "lux;let'") label value body))))
+ body
+ (reverse (as-pairs bindings)))
+ (#Ok [state (list output)]))))
(def (++ xs ys)
(case' xs
@@ -216,16 +215,16 @@
))
(defmacro (` tokens state)
- [(list (untemplate-list (map untemplate tokens)))
- state])
+ (#Ok [state
+ (list (untemplate-list (map untemplate tokens)))]))
(defmacro (if tokens state)
(case' tokens
(#Cons [test (#Cons [then (#Cons [else #Nil])])])
- [(` (case' (~ test)
- true (~ then)
- false (~ else)))
- state]))
+ (#Ok [state
+ (` (case' (~ test)
+ true (~ then)
+ false (~ else)))])))
(def (filter p xs)
(case' xs
@@ -239,13 +238,20 @@
(def (return val)
(lambda [state]
- [state val]))
+ (#Ok [state val])))
+
+(def (fail msg)
+ (lambda [_]
+ (#Error msg)))
(def (bind f v)
(lambda [state]
(case' (v state)
- [state' x]
- ((f x) state'))))
+ (#Ok [state' x])
+ (f x state')
+
+ (#Error msg)
+ (#Error msg))))
#(