diff --git a/README.md b/README.md index ec648fe..a376fc3 100644 --- a/README.md +++ b/README.md @@ -66,12 +66,6 @@ Positional values can be gotten out of lists using the `at` operator, and keys u 20 ``` -A shortcut for a key whose value is `true` looks like this, called a flag: -``` -> (list :yes) -(yes: true) -``` - #### Variables Variables are declared using `define` and `define-global`. Variables declared with `define` are available for use anywhere in subsequent expressions in the same scope, and `define-global` makes them globally available. ``` @@ -227,22 +221,12 @@ A function's parameter list can contain both positional and key parameters, wher 15 ``` -If the key's value is `true`, the same name as the key is used to bind the parameter's value. This makes it easy to define named parameters with flags: -``` -> (let f (fn (a b: true) (+ a b)) - (f 1 b: 2)) -3 -> (let f (fn (a :b) (+ a b)) ; use a flag - (f 10 b: 20)) -30 -``` - Parameters in Lumen are always optional, and those without a supplied argument have the value `nil`: ``` > (let f (fn (a) a) (f)) > -> (let f (fn (:b) (if (= b nil) 10 20)) +> (let f (fn (b: b) (if (= b nil) 10 20)) (f a: 99)) 10 ``` @@ -270,7 +254,7 @@ Variables can be bound to values in a list at certain positions or key: 2 > ((fn ((a b: my-b)) (list a my-b)) (list 1 b: 2)) (1 2) -> (let ((a :b) (list 1 b: 2)) +> (let ((a b: b) (list 1 b: 2)) b) 2 ``` @@ -279,7 +263,7 @@ The `rest` key works with destructuring as it does with function parameters, whi > (let ((a rest: as) (list 1 2 3)) (list a as)) (1 (2 3)) -> (let ((a :rest) (list 1 2 3)) +> (let ((a rest: rest) (list 1 2 3)) (list a rest)) (1 (2 3)) ``` diff --git a/bin/compiler.js b/bin/compiler.js index f0ca439..89f179d 100644 --- a/bin/compiler.js +++ b/bin/compiler.js @@ -503,22 +503,22 @@ ____x69.js = "!"; ____x69.lua = "not"; ____x68["not"] = ____x69; var ____x70 = []; -____x70["*"] = true; -____x70["/"] = true; -____x70["%"] = true; +____x70["*"] = "*"; +____x70["/"] = "/"; +____x70["%"] = "%"; var ____x71 = []; var ____x72 = []; ____x72.js = "+"; ____x72.lua = ".."; ____x71.cat = ____x72; var ____x73 = []; -____x73["+"] = true; -____x73["-"] = true; +____x73["+"] = "+"; +____x73["-"] = "-"; var ____x74 = []; -____x74["<"] = true; -____x74[">"] = true; -____x74["<="] = true; -____x74[">="] = true; +____x74["<"] = "<"; +____x74[">"] = ">"; +____x74["<="] = "<="; +____x74[">="] = ">="; var ____x75 = []; var ____x76 = []; ____x76.js = "==="; @@ -567,8 +567,12 @@ var getop = function (op) { if (__x82 === true) { return op; } else { - if (is63(__x82)) { - return __x82[target]; + if (string63(__x82)) { + return __x82; + } else { + if (is63(__x82)) { + return __x82[target]; + } } } }, infix); diff --git a/bin/compiler.lua b/bin/compiler.lua index 6768275..e34a2e3 100644 --- a/bin/compiler.lua +++ b/bin/compiler.lua @@ -454,22 +454,22 @@ ____x69.js = "!" ____x69.lua = "not" ____x68["not"] = ____x69 local ____x70 = {} -____x70["*"] = true -____x70["/"] = true -____x70["%"] = true +____x70["*"] = "*" +____x70["/"] = "/" +____x70["%"] = "%" local ____x71 = {} local ____x72 = {} ____x72.js = "+" ____x72.lua = ".." ____x71.cat = ____x72 local ____x73 = {} -____x73["+"] = true -____x73["-"] = true +____x73["+"] = "+" +____x73["-"] = "-" local ____x74 = {} -____x74["<"] = true -____x74[">"] = true -____x74["<="] = true -____x74[">="] = true +____x74["<"] = "<" +____x74[">"] = ">" +____x74["<="] = "<=" +____x74[">="] = ">=" local ____x75 = {} local ____x76 = {} ____x76.js = "===" @@ -513,8 +513,12 @@ local function getop(op) if __x82 == true then return op else - if is63(__x82) then - return __x82[target] + if string63(__x82) then + return __x82 + else + if is63(__x82) then + return __x82[target] + end end end end, infix) diff --git a/bin/reader.js b/bin/reader.js index b98c64e..b7b9dc6 100644 --- a/bin/reader.js +++ b/bin/reader.js @@ -71,9 +71,6 @@ read_string = function (str, more) { var key63 = function (atom) { return string63(atom) && _35(atom) > 1 && char(atom, edge(atom)) === ":"; }; -var flag63 = function (atom) { - return string63(atom) && _35(atom) > 1 && char(atom, 0) === ":"; -}; var expected = function (s, c) { var ____id1 = s; var __more = ____id1.more; @@ -146,17 +143,17 @@ read_table[""] = function (s) { }; read_table["("] = function (s) { read_char(s); - var __r16 = undefined; + var __r15 = undefined; var __l1 = []; - while (nil63(__r16)) { + while (nil63(__r15)) { skip_non_code(s); var __c4 = peek_char(s); if (__c4 === ")") { read_char(s); - __r16 = __l1; + __r15 = __l1; } else { if (nil63(__c4)) { - __r16 = expected(s, ")"); + __r15 = expected(s, ")"); } else { var __x2 = read(s); if (key63(__x2)) { @@ -164,31 +161,27 @@ read_table["("] = function (s) { var __v = read(s); __l1[__k] = __v; } else { - if (flag63(__x2)) { - __l1[clip(__x2, 1)] = true; - } else { - add(__l1, __x2); - } + add(__l1, __x2); } } } } - return __r16; + return __r15; }; read_table[")"] = function (s) { return error("Unexpected ) at " + s.pos); }; read_table["\""] = function (s) { read_char(s); - var __r19 = undefined; + var __r18 = undefined; var __str1 = "\""; - while (nil63(__r19)) { + while (nil63(__r18)) { var __c5 = peek_char(s); if (__c5 === "\"") { - __r19 = __str1 + read_char(s); + __r18 = __str1 + read_char(s); } else { if (nil63(__c5)) { - __r19 = expected(s, "\""); + __r18 = expected(s, "\""); } else { if (__c5 === "\\") { __str1 = __str1 + read_char(s); @@ -197,25 +190,25 @@ read_table["\""] = function (s) { } } } - return __r19; + return __r18; }; read_table["|"] = function (s) { read_char(s); - var __r21 = undefined; + var __r20 = undefined; var __str2 = "|"; - while (nil63(__r21)) { + while (nil63(__r20)) { var __c6 = peek_char(s); if (__c6 === "|") { - __r21 = __str2 + read_char(s); + __r20 = __str2 + read_char(s); } else { if (nil63(__c6)) { - __r21 = expected(s, "|"); + __r20 = expected(s, "|"); } else { __str2 = __str2 + read_char(s); } } } - return __r21; + return __r20; }; read_table["'"] = function (s) { read_char(s); diff --git a/bin/reader.lua b/bin/reader.lua index 6ccf399..eaca7e1 100644 --- a/bin/reader.lua +++ b/bin/reader.lua @@ -71,9 +71,6 @@ end local function key63(atom) return string63(atom) and _35(atom) > 1 and char(atom, edge(atom)) == ":" end -local function flag63(atom) - return string63(atom) and _35(atom) > 1 and char(atom, 0) == ":" -end local function expected(s, c) local ____id1 = s local __more = ____id1.more @@ -146,17 +143,17 @@ read_table[""] = function (s) end read_table["("] = function (s) read_char(s) - local __r16 = nil + local __r15 = nil local __l1 = {} - while nil63(__r16) do + while nil63(__r15) do skip_non_code(s) local __c4 = peek_char(s) if __c4 == ")" then read_char(s) - __r16 = __l1 + __r15 = __l1 else if nil63(__c4) then - __r16 = expected(s, ")") + __r15 = expected(s, ")") else local __x2 = read(s) if key63(__x2) then @@ -164,31 +161,27 @@ read_table["("] = function (s) local __v = read(s) __l1[__k] = __v else - if flag63(__x2) then - __l1[clip(__x2, 1)] = true - else - add(__l1, __x2) - end + add(__l1, __x2) end end end end - return __r16 + return __r15 end read_table[")"] = function (s) return error("Unexpected ) at " .. s.pos) end read_table["\""] = function (s) read_char(s) - local __r19 = nil + local __r18 = nil local __str1 = "\"" - while nil63(__r19) do + while nil63(__r18) do local __c5 = peek_char(s) if __c5 == "\"" then - __r19 = __str1 .. read_char(s) + __r18 = __str1 .. read_char(s) else if nil63(__c5) then - __r19 = expected(s, "\"") + __r18 = expected(s, "\"") else if __c5 == "\\" then __str1 = __str1 .. read_char(s) @@ -197,25 +190,25 @@ read_table["\""] = function (s) end end end - return __r19 + return __r18 end read_table["|"] = function (s) read_char(s) - local __r21 = nil + local __r20 = nil local __str2 = "|" - while nil63(__r21) do + while nil63(__r20) do local __c6 = peek_char(s) if __c6 == "|" then - __r21 = __str2 .. read_char(s) + __r20 = __str2 .. read_char(s) else if nil63(__c6) then - __r21 = expected(s, "|") + __r20 = expected(s, "|") else __str2 = __str2 .. read_char(s) end end end - return __r21 + return __r20 end read_table["'"] = function (s) read_char(s) diff --git a/compiler.l b/compiler.l index bdaa4e7..3e9517a 100644 --- a/compiler.l +++ b/compiler.l @@ -121,7 +121,7 @@ (= (hd x) 'unquote-splicing))) (define expand-local ((x name value)) - (setenv name :variable) + (setenv name variable: true) `(%local ,name ,(macroexpand value))) (define expand-function ((x args rest: body)) @@ -276,14 +276,14 @@ (add o x)))))) (define infix - `((not: (js: ! lua: ,"not")) - (:* :/ :%) + `((not: (js: ! lua: not)) + (*: * /: / %: %) (cat: (js: + lua: ..)) - (:+ :-) - (:< :> :<= :>=) + (+: + -: -) + (<: < >: > <=: <= >=: >=) (=: (js: === lua: ==)) (and: (js: && lua: and)) - (or: (js: ,"||" lua: or)))) + (or: (js: || lua: or)))) (define unary? (form) (and (two? form) (in? (hd form) '(not -)))) @@ -301,6 +301,7 @@ (find (fn (level) (let x (get level op) (if (= x true) op + (string? x) x (is? x) (get x target)))) infix)) @@ -345,7 +346,7 @@ (define compile-special (form stmt?) (let ((x rest: args) form - (:special :stmt tr: self-tr?) (getenv x) + (special: special stmt: stmt tr: self-tr?) (getenv x) tr (terminator (and stmt? (not self-tr?)))) (cat (apply special args) tr))) @@ -362,7 +363,7 @@ (cat "(" f1 ")" args) (cat f1 args)))) -(define op-delims (parent child :right) +(define op-delims (parent child right: right) (if ((if right >= >) (precedence child) (precedence parent)) @@ -372,7 +373,7 @@ (define compile-infix (form) (let ((op rest: (a b)) form (ao ac) (op-delims form a) - (bo bc) (op-delims form b :right) + (bo bc) (op-delims form b right: true) a (compile a) b (compile b) op (getop op)) @@ -380,14 +381,14 @@ (cat op ao " " a ac) (cat ao a ac " " op " " bo b bc)))) -(define-global compile-function (args body :name :prefix) +(define-global compile-function (args body name: name prefix: prefix) (let (id (if name (compile name) "") args1 (if (and (= target 'lua) (get args 'rest)) `(,@args |...|) args) args (compile-args args1) - body (with-indent (compile body :stmt)) + body (with-indent (compile body stmt: true)) ind (indentation) p (if prefix (cat prefix " ") "") tr (if (= target 'js) "" "end")) @@ -402,7 +403,7 @@ (and (not (= (hd form) 'return)) (not (statement? (hd form))))))) -(define-global compile (form :stmt) +(define-global compile (form stmt: stmt) (if (nil? form) "" (special-form? form) (compile-special form stmt) @@ -593,23 +594,23 @@ (define-global immediate-call? (x) (and (obj? x) (obj? (hd x)) (= (hd (hd x)) '%function))) -(define-special do forms :stmt :tr +(define-special do forms stmt: true tr: true (with s "" (step x forms (when (and (= target 'lua) (immediate-call? x) (= "\n" (char s (edge s)))) (set s (cat (clip s 0 (edge s)) ";\n"))) - (cat! s (compile x :stmt)) + (cat! s (compile x stmt: true)) (unless (atom? x) (if (or (= (hd x) 'return) (= (hd x) 'break)) (break)))))) -(define-special %if (cond cons alt) :stmt :tr +(define-special %if (cond cons alt) stmt: true tr: true (let (cond (compile cond) - cons (with-indent (compile cons :stmt)) - alt (if alt (with-indent (compile alt :stmt))) + cons (with-indent (compile cons stmt: true)) + alt (if alt (with-indent (compile alt stmt: true))) ind (indentation) s "") (if (= target 'js) @@ -622,53 +623,53 @@ (cat s ind "end\n") (cat s "\n")))) -(define-special while (cond form) :stmt :tr +(define-special while (cond form) stmt: true tr: true (let (cond (compile cond) - body (with-indent (compile form :stmt)) + body (with-indent (compile form stmt: true)) ind (indentation)) (if (= target 'js) (cat ind "while (" cond ") {\n" body ind "}\n") (cat ind "while " cond " do\n" body ind "end\n")))) -(define-special %for (t k form) :stmt :tr +(define-special %for (t k form) stmt: true tr: true (let (t (compile t) ind (indentation) - body (with-indent (compile form :stmt))) + body (with-indent (compile form stmt: true))) (if (= target 'lua) (cat ind "for " k " in next, " t " do\n" body ind "end\n") (cat ind "for (" k " in " t ") {\n" body ind "}\n")))) -(define-special %try (form) :stmt :tr +(define-special %try (form) stmt: true tr: true (let-unique (e) (let (ind (indentation) - body (with-indent (compile form :stmt)) + body (with-indent (compile form stmt: true)) hf `(return (%array false ,e)) - h (with-indent (compile hf :stmt))) + h (with-indent (compile hf stmt: true))) (cat ind "try {\n" body ind "}\n" ind "catch (" e ") {\n" h ind "}\n")))) -(define-special %delete (place) :stmt +(define-special %delete (place) stmt: true (cat (indentation) "delete " (compile place))) -(define-special break () :stmt +(define-special break () stmt: true (cat (indentation) "break")) (define-special %function (args body) (compile-function args body)) -(define-special %global-function (name args body) :stmt :tr +(define-special %global-function (name args body) stmt: true tr: true (if (= target 'lua) (let x (compile-function args body name: name) (cat (indentation) x)) - (compile `(%set ,name (%function ,args ,body)) :stmt))) + (compile `(%set ,name (%function ,args ,body)) stmt: true))) -(define-special %local-function (name args body) :stmt :tr +(define-special %local-function (name args body) stmt: true tr: true (if (= target 'lua) (let x (compile-function args body name: name prefix: 'local) (cat (indentation) x)) - (compile `(%local ,name (%function ,args ,body)) :stmt))) + (compile `(%local ,name (%function ,args ,body)) stmt: true))) -(define-special return (x) :stmt +(define-special return (x) stmt: true (let x (if (nil? x) "return" (cat "return " (compile x))) @@ -680,13 +681,13 @@ (define-special typeof (x) (cat "typeof(" (compile x) ")")) -(define-special throw (x) :stmt +(define-special throw (x) stmt: true (let e (if (= target 'js) (cat "throw " (compile x)) (cat "error(" (compile x) ")")) (cat (indentation) e))) -(define-special %local (name value) :stmt +(define-special %local (name value) stmt: true (let (id (compile name) value1 (compile value) rh (if (is? value) (cat " = " value1) "") @@ -694,7 +695,7 @@ ind (indentation)) (cat ind keyword id rh))) -(define-special %set (lh rh) :stmt +(define-special %set (lh rh) stmt: true (let (lh (compile lh) rh (compile (if (nil? rh) 'nil rh))) (cat (indentation) lh " = " rh))) diff --git a/macros.l b/macros.l index bac6bd6..087ab3d 100644 --- a/macros.l +++ b/macros.l @@ -96,13 +96,13 @@ `(set (get read-table ,char) (fn (,s) ,@body))) (define-macro define (name x rest: body) - (setenv name :variable) + (setenv name variable: true) (if (some? body) `(%local-function ,name ,@(bind* x body)) `(%local ,name ,x))) (define-macro define-global (name x rest: body) - (setenv name :toplevel :variable) + (setenv name toplevel: true variable: true) (if (some? body) `(%global-function ,name ,@(bind* x body)) `(set ,name ,x))) @@ -117,7 +117,7 @@ (let-unique (x) `(with-frame (each ,x ,names - (setenv ,x :variable)) + (setenv ,x variable: true)) ,@body))) (define-macro let-macro (definitions rest: body) diff --git a/main.l b/main.l index 743303a..3751e82 100644 --- a/main.l +++ b/main.l @@ -36,7 +36,7 @@ (let (s ((get reader 'stream) ((get system 'read-file) path)) body ((get reader 'read-all) s) form ((get compiler 'expand) `(do ,@body))) - ((get compiler 'compile) form :stmt))) + ((get compiler 'compile) form stmt: true))) (define-global load (path) (let previous target diff --git a/reader.l b/reader.l index 9deb5d1..e483eee 100644 --- a/reader.l +++ b/reader.l @@ -5,7 +5,7 @@ (obj pos: 0 string: str len: (# str) more: more)) (define peek-char (s) - (let ((:pos :len :string) s) + (let ((pos: pos len: len string: string) s) (when (< pos len) (char string pos)))) @@ -52,13 +52,8 @@ (> (# atom) 1) (= (char atom (edge atom)) ":"))) -(define flag? (atom) - (and (string? atom) - (> (# atom) 1) - (= (char atom 0) ":"))) - (define expected (s c) - (let ((:more :pos) s) + (let ((more: more pos: pos) s) (or more (error (cat "Expected " c " at " pos))))) (define wrap (s x) @@ -108,7 +103,6 @@ (let (k (clip x 0 (edge x)) v (read s)) (set (get l k) v)) - (flag? x) (set (get l (clip x 1)) true) (add l x))))))))) (define-reader (")" s) diff --git a/test.l b/test.l index 30a6d0b..12d69c6 100755 --- a/test.l +++ b/test.l @@ -57,7 +57,6 @@ (test= '(quasiquote (unquote-splicing a)) (read "`,@a")) (test= 2 (# (read "(1 2 a: 7)"))) (test= 7 (get (read "(1 2 a: 7)") 'a)) - (test= true (get (read "(:a)") 'a)) (test= 1 (- -1)) (test= "0?" (read "0?")) (test= "0!" (read "0!")) @@ -249,10 +248,6 @@ c" (test= '(1 2 3) (list 1 2 3)) (test= 17 (get (list foo: 17) 'foo)) (test= 17 (get (list 1 foo: 17) 'foo)) - (test= true (get (list :foo) 'foo)) - (test= true (get '(:foo) 'foo)) - (test= true (get (hd '((:foo))) 'foo)) - (test= '(:a) (list :a)) (test= '(b: false) (list b: false)) (test= '(c: 0) (list c: 0))) @@ -287,7 +282,6 @@ c" (let a 42 (test= '(quasiquote ((unquote-splicing (list a)))) ``(,@(list a))) (test= '(quasiquote ((unquote-splicing (list 42)))) ``(,@(list ,a)))) - (test= true (get `(:foo) 'foo)) (let (a 17 b '(1 2) c (obj a: 10) @@ -296,13 +290,8 @@ c" (test= 2 (# `(foo: ,a ,@b))) (test= 17 (get `(foo: ,@a) 'foo)) (test= '(1 a: 10) `(1 ,@c)) - (test= '(1 a: 10) `(1 ,@d)) - (test= true (get (hd `((:foo))) 'foo)) - (test= true (get (hd `(,(list :foo))) 'foo)) - (test= true (get `(,@(list :foo)) 'foo)) - (test= true (get `(1 2 3 ,@'(:foo)) 'foo))) + (test= '(1 a: 10) `(1 ,@d))) (let-macro ((a keys `(obj ,@keys))) - (test= true (get (a :foo) 'foo)) (test= 17 (get (a bar: 17) 'bar))) (let-macro ((a () `(obj baz: (fn () 17)))) (test= 17 ((get (a) 'baz))))) @@ -379,7 +368,7 @@ c" (test= nil a))) (define-test wipe - (let x '(:a :b :c) + (let x '(a: true b: true c: true) (wipe (get x 'a)) (test= nil (get x 'a)) (test= true (get x 'b)) @@ -480,15 +469,14 @@ c" (test= 3 n))) (define-test table - (test= 10 (get (obj a: 10) 'a)) - (test= true (get (obj :a) 'a))) + (test= 10 (get (obj a: 10) 'a))) (define-test empty (test= true (empty? ())) (test= true (empty? (obj))) (test= false (empty? '(1))) - (test= false (empty? '(:a))) - (test= false (empty? (obj :a))) + (test= false (empty? '(a: true))) + (test= false (empty? (obj a: true))) (test= false (empty? '(b: false)))) (define-test at @@ -514,7 +502,7 @@ c" (test= nil (get t2 'foo)))) (define-test each - (let t '(1 2 3 :a b: false) + (let t '(1 2 3 a: true b: false) (let (a 0 b 0) (each (k v) t (if (number? k) @@ -543,7 +531,7 @@ c" (test= 10 n)) (let xs () (let l (list (obj a: 1 b: 2) (obj a: 2 b: 4)) - (step (:a :b) l + (step (a: a b: b) l (add xs (+ a b)))) (test= '(3 6) xs)) (let l '(a b) @@ -718,20 +706,20 @@ c" (let ((w (x rest: y) rest: z) '(1 (2 3 4) 5 6 7)) (test= '(3 4) y) (test= '(5 6 7) z)) - (let ((:foo) (obj foo: 99)) + (let ((foo: foo) (obj foo: 99)) (test= 99 foo)) - (let ((:foo) (list foo: 99)) + (let ((foo: foo) (list foo: 99)) (test= 99 foo)) (let ((foo: a) (obj foo: 99)) (test= 99 a)) (let ((foo: (a b)) (obj foo: '(98 99))) (test= 98 a) (test= 99 b)) - (let ((:foo bar: (:baz)) - (obj foo: 42 bar: '(99 :baz))) + (let ((foo: foo bar: (baz: baz)) + (obj foo: 42 bar: '(99 baz: true))) (test= 42 foo) (test= true baz)) - (let ((a (b :foo) :bar) + (let ((a (b foo: foo) bar: bar) (list 10 (list 20 foo: 17) bar: '(1 2 3))) (test= 10 a) (test= 20 b) @@ -866,10 +854,10 @@ c" (test= '(a) (join '(a) ())) (test= '(a) (join nil '(a))) (test= '(a) (join '(a))) - (test= '(a :b) (join '(a) (obj :b))) - (test= '(a b :b) (join '(a) '(b :b))) - (test= '(a b: 10) (join '(a :b) (obj b: 10))) - (test= '(b: 10) (join (obj :b) '(b: 10))) + (test= '(a b: true) (join '(a) (obj b: true))) + (test= '(a b b: true) (join '(a) '(b b: true))) + (test= '(a b: 10) (join '(a b: true) (obj b: 10))) + (test= '(b: 10) (join (obj b: true) '(b: 10))) (let t (join '(a b: 1) '(b c: 2)) (test= 1 (get t 'b)) (test= 2 (get t 'c)) @@ -878,16 +866,16 @@ c" (define-test reverse (test= () (reverse ())) (test= '(3 2 1) (reverse '(1 2 3))) - (test= '(3 2 1 :a) (reverse '(1 2 3 :a)))) + (test= '(3 2 1 a: true) (reverse '(1 2 3 a: true)))) (define-test map (test= () (map (fn (x) x) ())) (test= '(1) (map (fn (x) x) '(1))) (test= '(2 3 4) (map (fn (x) (+ x 1)) '(1 2 3))) (test= '(2 3 4 a: 5) (map (fn (x) (+ x 1)) (list 1 2 3 a: 4))) - (test= '(:a) (map (fn (x) x) '(:a))) + (test= '(a: true) (map (fn (x) x) '(a: true))) (test= '(b: false) (map (fn (x) x) '(b: false))) - (test= '(:a b: false) (map (fn (x) x) '(:a b: false))) + (test= '(a: true b: false) (map (fn (x) x) '(a: true b: false))) (let evens (fn (x) (when (= (% x 2) 0) x)) (test= '(2 4 6) (map evens '(1 2 3 4 5 6))) (test= '(2 4 6 b: 8) (map evens '(1 2 3 4 5 6 a: 7 b: 8))))) @@ -900,12 +888,12 @@ c" (test= '(1 2 3) (cut '(1 2 3) 0 10)) (test= '(1) (cut '(1 2 3) -4 1)) (test= '(1 2 3) (cut '(1 2 3) -4)) - (test= '(2 :a) (cut '(1 2 :a) 1)) - (test= '(:a b: 2) (cut '(:a b: 2))) + (test= '(2 a: true) (cut '(1 2 a: true) 1)) + (test= '(a: true b: 2) (cut '(a: true b: 2))) (let t '(1 2 3) (test= () (cut t (# t)))) - (let t '(1 2 3 :a) - (test= '(:a) (cut t (# t))))) + (let t '(1 2 3 a: true) + (test= '(a: true) (cut t (# t))))) (define-test clip (test= "uux" (clip "quux" 1)) @@ -966,10 +954,10 @@ c" (test= 7 (find (fn (x) x) '(7))) (test= true (find (fn (x) (= x 7)) '(2 4 7))) (test= true (find (fn (x) (= x 7)) '(2 4 foo: 7))) - (test= true (find (fn (x) (= x true)) '(2 4 :bar))) + (test= true (find (fn (x) (= x true)) '(2 4 bar: true))) (test= true (in? 7 '(2 4 7))) (test= true (in? 7 '(2 4 foo: 7))) - (test= true (in? true '(2 4 :bar)))) + (test= true (in? true '(2 4 bar: true)))) (define-test first (test= nil (first (fn (x) x) ())) @@ -1025,8 +1013,8 @@ c" (let t '(1) (set (get t 'foo) 17) (test= 17 (apply (fn a (get a 'foo)) t))) - (test= 42 (apply (fn (:foo) foo) (list foo: 42))) - (test= 42 (apply (fn ((:foo)) foo) (list (list foo: 42)))) + (test= 42 (apply (fn (foo: foo) foo) (list foo: 42))) + (test= 42 (apply (fn ((foo: foo)) foo) (list (list foo: 42)))) (test= 116 (apply + 1 5 '(100 10)))) (define-test eval @@ -1055,22 +1043,22 @@ c" (test= '(3 4) ((fn (a b rest: c) c) 1 2 3 4)) (let f (fn (w (x rest: y) rest: z) (list y z)) (test= '((3 4) (5 6 7)) (f 1 '(2 3 4) 5 6 7))) - (test= 42 ((fn (:foo) foo) foo: 42)) - (test= 42 (apply (fn (:foo) foo) '(foo: 42))) - (test= 42 ((fn ((:foo)) foo) (list foo: 42))) - (let f (fn (a bar: b (:foo)) (list a b foo)) + (test= 42 ((fn (foo: foo) foo) foo: 42)) + (test= 42 (apply (fn (foo: foo) foo) '(foo: 42))) + (test= 42 ((fn ((foo: foo)) foo) (list foo: 42))) + (let f (fn (a bar: b (foo: foo)) (list a b foo)) (test= '(10 20 42) (f 10 bar: 20 (list foo: 42)))) - (let f (fn (a bar: b (:foo)) (list a b foo)) + (let f (fn (a bar: b (foo: foo)) (list a b foo)) (test= '(10 20 42) (apply f '(10 bar: 20 (foo: 42))))) - (test= 1 ((fn (a :b) (+ (or a 0) b)) b: 1)) - (test= 1 (apply (fn (a :b) (+ (or a 0) b)) (list b: 1))) + (test= 1 ((fn (a b: b) (+ (or a 0) b)) b: 1)) + (test= 1 (apply (fn (a b: b) (+ (or a 0) b)) (list b: 1))) (let f (fn args args) (test= '(1 2 3) (f 1 2 3))) (let f (fn args args) (test= '(1 2 3) (apply f (list 1 2 3)))) (let l () - (define f (:a) (add l a) a) - (define g (a b :c) (add l (list a b c)) c) + (define f (a: a) (add l a) a) + (define g (a b c: c) (add l (list a b c)) c) (test= 42 (f a: (g (f a: 10) (f a: 20) c: (f a: 42)))) (test= '(10 20 42 (10 20 42) 42) l)) (let l nil