From 03dbd79165098a4b74470cc767431534701f6b0e Mon Sep 17 00:00:00 2001 From: Calvin Rose Date: Sun, 16 Dec 2018 21:57:32 -0500 Subject: [PATCH] Rename the := special form to set so it does not look like a keyword. --- doc/Introduction.md | 6 +- examples/lazyseqs.janet | 4 +- examples/life.janet | 4 +- examples/primes.janet | 2 +- grammar/janet.tmLanguage | 16 ++--- src/core/core.janet | 138 +++++++++++++++++++------------------- src/core/specials.c | 3 +- src/mainclient/init.janet | 12 ++-- test/helper.janet | 2 +- test/suite0.janet | 22 +++--- test/suite1.janet | 4 +- 11 files changed, 106 insertions(+), 107 deletions(-) diff --git a/doc/Introduction.md b/doc/Introduction.md index 809cd19f..c4eb87f4 100644 --- a/doc/Introduction.md +++ b/doc/Introduction.md @@ -83,7 +83,7 @@ return a real number (never an integer!) Janet supports several varieties of types that can be used as labels for things in your program. The most useful type for this purpose is the keyword type. A keyword begins with a semicolon, and then contains 0 or more alphanumeric or a few other common -characters. For example, `:hello`, `:my-name`, `:=`, and `:ABC123_-*&^%$` are all keywords. +characters. For example, `:hello`, `:my-name`, `::`, and `:ABC123_-*&^%$` are all keywords. Keywords are actually just special cases of symbols, which are similar but don't start with a semicolon. The difference between symbols and keywords is that keywords evaluate to themselves, while symbols evaluate to whatever they are bound to. To have a symbol evaluate to itself, it must be @@ -247,13 +247,13 @@ symbols will raise an error. Bindings created with def have lexical scoping. Also, bindings created with def are immutable; they cannot be changed after definition. For mutable bindings, like variables in other programming -languages, use the `var` keyword. The assignment special form `:=` can then be used to update +languages, use the `var` keyword. The assignment special form `set` can then be used to update a var. ``` (var myvar 1) (print myvar) -(:= myvar 10) +(set myvar 10) (print myvar) ``` diff --git a/examples/lazyseqs.janet b/examples/lazyseqs.janet index 3ed21a7a..e024e44b 100644 --- a/examples/lazyseqs.janet +++ b/examples/lazyseqs.janet @@ -18,8 +18,8 @@ (if ,loaded ,state (do - (:= ,loaded true) - (:= ,state (do ;forms))))))) + (set ,loaded true) + (set ,state (do ;forms))))))) # Use tuples instead of structs to save memory (def- HEAD 0) diff --git a/examples/life.janet b/examples/life.janet index 846acd22..64b82988 100644 --- a/examples/life.janet +++ b/examples/life.janet @@ -24,7 +24,7 @@ "Draw cells in the game of life from (x1, y1) to (x2, y2)" [state x1 y1 x2 y2] (def cellset @{}) - (each cell state (:= cellset@cell true)) + (each cell state (set cellset@cell true)) (loop [x :range [x1 (+ 1 x2)] :after (print) y :range [y1 (+ 1 y2)]] @@ -40,4 +40,4 @@ (for i 0 20 (print "generation " i) (draw *state* -7 -7 7 7) - (:= *state* (tick *state*))) + (set *state* (tick *state*))) diff --git a/examples/primes.janet b/examples/primes.janet index 6cf80693..38cc91fe 100644 --- a/examples/primes.janet +++ b/examples/primes.janet @@ -9,6 +9,6 @@ (def len (length list)) (for j 0 len (def trial (get list j)) - (if (zero? (% i trial)) (:= isprime? false))) + (if (zero? (% i trial)) (set isprime? false))) (if isprime? (array/push list i))) list) diff --git a/grammar/janet.tmLanguage b/grammar/janet.tmLanguage index f9f036a1..ef8cf7f7 100644 --- a/grammar/janet.tmLanguage +++ b/grammar/janet.tmLanguage @@ -205,53 +205,53 @@ name punctuation.other.janet - + literal match - (?<![\.:\w_\-=!@\$%^&?|\\/<>])(true|false|nil)(?![\.:\w_\-=!@\$%^&?|\\/<>]) + (?<![\.:\w_\-=!@\$%^&?|\\/<>*])(true|false|nil)(?![\.:\w_\-=!@\$%^&?|\\/<>*]) name constant.language.janet corelib match - (?<![\.:\w_\-=!@\$%^&?|\\/<>])(def|do|fn|if|quasiquote|quote|splice|unquote|while|%|%=|&|&=|\*|\*=|\*doc\-width\*|\*env\*|\+|\+\+|\+=|\-|\-\-|\-=|\->|\->>|/|/=|<|<<|<<=|<=|=|==|>|>=|>>|>>=|>>>|>>>=|\^|\^=|_env|abstract\?|all|all\-symbols|and|apply|array|array/concat|array/ensure|array/insert|array/new|array/peek|array/pop|array/push|array/slice|array\?|asm|bnot|boolean\?|buffer|buffer/clear|buffer/new|buffer/popn|buffer/push\-byte|buffer/push\-integer|buffer/push\-string|buffer/slice|buffer\?|bytes\?|callable\?|case|cfunction\?|comment|comp|compile|complement|cond|coro|count|debug|debug/arg\-stack|debug/break|debug/fbreak|debug/lineage|debug/stack|debug/unbreak|debug/unfbreak|dec|deep\-not=|deep=|def\-|default|defglobal|defmacro|defmacro\-|defn|defn\-|describe|dictionary\?|disasm|distinct|doc|doc\*|doc\-format|drop\-until|drop\-while|each|empty\?|env\-lookup|error|eval|eval\-string|even\?|every\?|extreme|false\?|fiber/current|fiber/maxstack|fiber/new|fiber/setmaxstack|fiber/status|fiber\?|file/close|file/flush|file/open|file/popen|file/read|file/seek|file/write|filter|find|find\-index|first|flatten|flatten\-into|for|frequencies|function\?|gccollect|gcinterval|gcsetinterval|generate|gensym|get|getline|hash|idempotent\?|identity|if\-let|if\-not|import|import\*|inc|indexed\?|int|integer\?|interleave|interpose|invert|janet/build|janet/version|juxt|juxt\*|keep|keys|keyword\?|kvs|last|length|let|loop|macex|macex1|make\-env|map|mapcat|marshal|match|match\-1|math/acos|math/asin|math/atan|math/ceil|math/cos|math/e|math/exp|math/floor|math/inf|math/log|math/log10|math/pi|math/pow|math/random|math/seedrandom|math/sin|math/sqrt|math/tan|max|max\-order|merge|merge\-into|min|min\-order|module/find|module/native\-paths|module/paths|native|neg\?|next|nil\?|not|not=|not==|number\?|odd\?|one\?|or|order<|order<=|order>|order>=|os/clock|os/cwd|os/execute|os/exit|os/getenv|os/setenv|os/shell|os/sleep|os/time|os/which|pairs|parser/byte|parser/consume|parser/error|parser/flush|parser/new|parser/produce|parser/state|parser/status|parser/where|partial|pos\?|print|process/args|product|put|range|real|real\?|reduce|repl|require|resume|reverse|run\-context|scan\-integer|scan\-number|scan\-real|sentinel|seq|some|sort|sorted|status\-pp|stderr|stdin|stdout|string|string/ascii\-lower|string/ascii\-upper|string/bytes|string/check\-set|string/find|string/find\-all|string/from\-bytes|string/join|string/number|string/pretty|string/repeat|string/replace|string/replace\-all|string/reverse|string/slice|string/split|string\?|struct|struct\?|sum|symbol|symbol\?|table|table/getproto|table/new|table/rawget|table/setproto|table/to\-struct|table\?|take\-until|take\-while|true\?|tuple|tuple/append|tuple/prepend|tuple/slice|tuple\?|type|unless|unmarshal|update|values|varglobal|when|when\-let|with\-idemp|yield|zero\?|zipcoll|\||\|=)(?![\.:\w_\-=!@\$%^&?|\\/<>]) + (?<![\.:\w_\-=!@\$%^&?|\\/<>*])(def|do|fn|if|quasiquote|quote|set|splice|unquote|var|while|%|%=|&|&=|\*|\*=|\*doc\-width\*|\*env\*|\+|\+\+|\+=|\-|\-\-|\-=|\->|\->>|/|/=|<|<<|<<=|<=|=|==|>|>=|>>|>>=|>>>|>>>=|\^|\^=|_env|abstract\?|all|all\-symbols|and|apply|array|array/concat|array/ensure|array/insert|array/new|array/peek|array/pop|array/push|array/slice|array\?|asm|bnot|boolean\?|buffer|buffer/clear|buffer/new|buffer/popn|buffer/push\-byte|buffer/push\-integer|buffer/push\-string|buffer/slice|buffer\?|bytes\?|callable\?|case|cfunction\?|comment|comp|compile|complement|cond|coro|count|debug|debug/arg\-stack|debug/break|debug/fbreak|debug/lineage|debug/stack|debug/unbreak|debug/unfbreak|dec|deep\-not=|deep=|def\-|default|defglobal|defmacro|defmacro\-|defn|defn\-|describe|dictionary\?|disasm|distinct|doc|doc\*|doc\-format|drop\-until|drop\-while|each|empty\?|env\-lookup|error|eval|eval\-string|even\?|every\?|extreme|false\?|fiber/current|fiber/maxstack|fiber/new|fiber/setmaxstack|fiber/status|fiber\?|file/close|file/flush|file/open|file/popen|file/read|file/seek|file/write|filter|find|find\-index|first|flatten|flatten\-into|for|frequencies|function\?|gccollect|gcinterval|gcsetinterval|generate|gensym|get|getline|hash|idempotent\?|identity|if\-let|if\-not|import|import\*|inc|indexed\?|int|integer\?|interleave|interpose|invert|janet/build|janet/version|juxt|juxt\*|keep|keys|keyword\?|kvs|last|length|let|loop|macex|macex1|make\-env|map|mapcat|marshal|match|match\-1|math/acos|math/asin|math/atan|math/ceil|math/cos|math/e|math/exp|math/floor|math/inf|math/log|math/log10|math/pi|math/pow|math/random|math/seedrandom|math/sin|math/sqrt|math/tan|max|max\-order|merge|merge\-into|min|min\-order|module/find|module/native\-paths|module/paths|native|neg\?|next|nil\?|not|not=|not==|number\?|odd\?|one\?|or|order<|order<=|order>|order>=|os/clock|os/cwd|os/execute|os/exit|os/getenv|os/setenv|os/shell|os/sleep|os/time|os/which|pairs|parser/byte|parser/consume|parser/error|parser/flush|parser/new|parser/produce|parser/state|parser/status|parser/where|partial|pos\?|print|process/args|product|put|range|real|real\?|reduce|repl|require|resume|reverse|run\-context|scan\-integer|scan\-number|scan\-real|sentinel|seq|some|sort|sorted|status\-pp|stderr|stdin|stdout|string|string/ascii\-lower|string/ascii\-upper|string/bytes|string/check\-set|string/find|string/find\-all|string/from\-bytes|string/join|string/number|string/pretty|string/repeat|string/replace|string/replace\-all|string/reverse|string/slice|string/split|string\?|struct|struct\?|sum|symbol|symbol\?|table|table/getproto|table/new|table/rawget|table/setproto|table/to\-struct|table\?|take\-until|take\-while|true\?|tuple|tuple/append|tuple/prepend|tuple/slice|tuple\?|type|unless|unmarshal|update|values|varglobal|when|when\-let|with\-idemp|yield|zero\?|zipcoll|\||\|=)(?![\.:\w_\-=!@\$%^&?|\\/<>*]) name keyword.control.janet keysym match - (?<![\.:\w_\-=!@\$%^&?|\\/<>]):[\.:\w_\-=!@\$%^&?|\\/<>]* + (?<![\.:\w_\-=!@\$%^&?|\\/<>*]):[\.:\w_\-=!@\$%^&?|\\/<>*]* name constant.keyword.janet symbol match - (?<![\.:\w_\-=!@\$%^&?|\\/<>])[\.a-zA-Z_\-=!@\$%^&?|\\/<>][\.:\w_\-=!@\$%^&?|\\/<>]* + (?<![\.:\w_\-=!@\$%^&?|\\/<>*])[\.a-zA-Z_\-=!@\$%^&?|\\/<>*][\.:\w_\-=!@\$%^&?|\\/<>*]* name variable.other.janet hex-number match - (?<![\.:\w_\-=!@\$%^&?|\\/<>])[-+]?0x([_\da-fA-F]+|[_\da-fA-F]+\.[_\da-fA-F]*|\.[_\da-fA-F]+)(&[+-]?[\da-fA-F]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>]) + (?<![\.:\w_\-=!@\$%^&?|\\/<>*])[-+]?0x([_\da-fA-F]+|[_\da-fA-F]+\.[_\da-fA-F]*|\.[_\da-fA-F]+)(&[+-]?[\da-fA-F]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>*]) name constant.numeric.hex.janet dec-number match - (?<![\.:\w_\-=!@\$%^&?|\\/<>])[-+]?([_\d]+|[_\d]+\.[_\d]*|\.[_\d]+)([eE&][+-]?[\d]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>]) + (?<![\.:\w_\-=!@\$%^&?|\\/<>*])[-+]?([_\d]+|[_\d]+\.[_\d]*|\.[_\d]+)([eE&][+-]?[\d]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>*]) name constant.numeric.decimal.janet r-number match - (?<![\.:\w_\-=!@\$%^&?|\\/<>])[-+]?\d\d?r([_\w]+|[_\w]+\.[_\w]*|\.[_\w]+)(&[+-]?[\w]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>]) + (?<![\.:\w_\-=!@\$%^&?|\\/<>*])[-+]?\d\d?r([_\w]+|[_\w]+\.[_\w]*|\.[_\w]+)(&[+-]?[\w]+)?(?![\.:\w_\-=!@\$%^&?|\\/<>*]) name constant.numeric.decimal.janet diff --git a/src/core/core.janet b/src/core/core.janet index 2da8391b..fe70455d 100644 --- a/src/core/core.janet +++ b/src/core/core.janet @@ -25,7 +25,7 @@ i (do (if (= t :string) - (:= docstr ith) + (set docstr ith) (array/push modifiers ith)) (if (< i len) (recur (+ i 1))))))) (def start (fstart 0)) @@ -37,7 +37,7 @@ (while (< index arglen) (buffer/push-string buf " ") (string/pretty args.index 4 buf) - (:= index (+ index 1))) + (set index (+ index 1))) (array/push modifiers (string buf ")\n\n" docstr)) # Build return value ~(def ,name ,;modifiers (fn ,name ,;(tuple/slice more start))))) @@ -149,19 +149,19 @@ # C style macros and functions for imperative sugar (defn inc "Returns x + 1." [x] (+ x 1)) (defn dec "Returns x - 1." [x] (- x 1)) -(defmacro ++ "Increments the var x by 1." [x] ~(:= ,x (,+ ,x ,1))) -(defmacro -- "Decrements the var x by 1." [x] ~(:= ,x (,- ,x ,1))) -(defmacro += "Increments the var x by n." [x n] ~(:= ,x (,+ ,x ,n))) -(defmacro -= "Decrements the vat x by n." [x n] ~(:= ,x (,- ,x ,n))) -(defmacro *= "Shorthand for (:= x (* x n))." [x n] ~(:= ,x (,* ,x ,n))) -(defmacro /= "Shorthand for (:= x (/ x n))." [x n] ~(:= ,x (,/ ,x ,n))) -(defmacro %= "Shorthand for (:= x (% x n))." [x n] ~(:= ,x (,% ,x ,n))) -(defmacro &= "Shorthand for (:= x (& x n))." [x n] ~(:= ,x (,& ,x ,n))) -(defmacro |= "Shorthand for (:= x (| x n))." [x n] ~(:= ,x (,| ,x ,n))) -(defmacro ^= "Shorthand for (:= x (^ x n))." [x n] ~(:= ,x (,^ ,x ,n))) -(defmacro >>= "Shorthand for (:= x (>> x n))." [x n] ~(:= ,x (,>> ,x ,n))) -(defmacro <<= "Shorthand for (:= x (<< x n))." [x n] ~(:= ,x (,<< ,x ,n))) -(defmacro >>>= "Shorthand for (:= x (>>> x n))." [x n] ~(:= ,x (,>>> ,x ,n))) +(defmacro ++ "Increments the var x by 1." [x] ~(set ,x (,+ ,x ,1))) +(defmacro -- "Decrements the var x by 1." [x] ~(set ,x (,- ,x ,1))) +(defmacro += "Increments the var x by n." [x n] ~(set ,x (,+ ,x ,n))) +(defmacro -= "Decrements the vat x by n." [x n] ~(set ,x (,- ,x ,n))) +(defmacro *= "Shorthand for (set x (* x n))." [x n] ~(set ,x (,* ,x ,n))) +(defmacro /= "Shorthand for (set x (/ x n))." [x n] ~(set ,x (,/ ,x ,n))) +(defmacro %= "Shorthand for (set x (% x n))." [x n] ~(set ,x (,% ,x ,n))) +(defmacro &= "Shorthand for (set x (& x n))." [x n] ~(set ,x (,& ,x ,n))) +(defmacro |= "Shorthand for (set x (| x n))." [x n] ~(set ,x (,| ,x ,n))) +(defmacro ^= "Shorthand for (set x (^ x n))." [x n] ~(set ,x (,^ ,x ,n))) +(defmacro >>= "Shorthand for (set x (>> x n))." [x n] ~(set ,x (,>> ,x ,n))) +(defmacro <<= "Shorthand for (set x (<< x n))." [x n] ~(set ,x (,<< ,x ,n))) +(defmacro >>>= "Shorthand for (set x (>>> x n))." [x n] ~(set ,x (,>>> ,x ,n))) (defmacro default "Define a default value for an optional argument. @@ -248,7 +248,7 @@ (var i len) (while (> i 0) (-- i) - (:= ret (if (= ret true) + (set ret (if (= ret true) forms.i (tuple 'if forms.i ret)))) ret) @@ -263,7 +263,7 @@ (while (> i 0) (-- i) (def fi forms.i) - (:= ret (if (idempotent? fi) + (set ret (if (idempotent? fi) (tuple 'if fi fi ret) (do (def $fi (gensym)) @@ -331,13 +331,13 @@ (tuple 'var $iter 0) (tuple 'while (tuple/slice spreds) - (tuple := $iter (tuple + 1 $iter)) + (tuple 'set $iter (tuple + 1 $iter)) sub))) (error (string "unexpected loop predicate: " bindings))) (case verb :iterate (do (def $iter (gensym)) - (def preds @['and (tuple ':= $iter object)]) + (def preds @['and (tuple 'set $iter object)]) (def subloop (doone (+ i 3) preds)) (tuple 'do (tuple 'var $iter nil) @@ -357,7 +357,7 @@ (tuple 'while (tuple/slice preds) (tuple 'def bindings $iter) subloop - (tuple ':= $iter (tuple + $iter inc))))) + (tuple 'set $iter (tuple + $iter inc))))) :keys (do (def $dict (gensym)) (def $iter (gensym)) @@ -369,7 +369,7 @@ (tuple 'while (tuple/slice preds) (tuple 'def bindings $iter) subloop - (tuple ':= $iter (tuple next $dict $iter))))) + (tuple 'set $iter (tuple next $dict $iter))))) :in (do (def $len (gensym)) (def $i (gensym)) @@ -383,7 +383,7 @@ (tuple 'while (tuple/slice preds 0) (tuple 'def bindings (tuple get $indexed $i)) subloop - (tuple ':= $i (tuple + 1 $i))))) + (tuple 'set $i (tuple + 1 $i))))) :generate (do (def $fiber (gensym)) (def $yieldval (gensym)) @@ -400,7 +400,7 @@ (tuple 'while (tuple/slice preds 0) (tuple 'def bindings $yieldval) subloop - (tuple := $yieldval (tuple resume $fiber))))) + (tuple 'set $yieldval (tuple resume $fiber))))) (error (string "unexpected loop verb: " verb))))))) (doone 0 nil)) @@ -517,7 +517,7 @@ (var ret args.0) (loop [i :range [0 len]] (def v args.i) - (if (order v ret) (:= ret v))) + (if (order v ret) (set ret v))) ret)) (defn max @@ -566,11 +566,11 @@ (def aj a.j) (when (by aj pivot) (def ai a.i) - (:= a.i aj) - (:= a.j ai) + (set a.i aj) + (set a.j ai) (++ i))) - (:= a.hi a.i) - (:= a.i pivot) + (set a.hi a.i) + (set a.i pivot) i) (defn sort-help @@ -595,7 +595,7 @@ [f init ind] (var res init) (loop [x :in ind] - (:= res (f res x))) + (set res (f res x))) res) (defn map @@ -607,18 +607,18 @@ (var limit (length inds.0)) (loop [i :range [0 ninds]] (def l (length inds.i)) - (if (< l limit) (:= limit l))) + (if (< l limit) (set limit l))) (def [i1 i2 i3 i4] inds) (def res (array/new limit)) (case ninds - 1 (loop [i :range [0 limit]] (:= res.i (f i1.i))) - 2 (loop [i :range [0 limit]] (:= res.i (f i1.i i2.i))) - 3 (loop [i :range [0 limit]] (:= res.i (f i1.i i2.i i3.i))) - 4 (loop [i :range [0 limit]] (:= res.i (f i1.i i2.i i3.i i4.i))) + 1 (loop [i :range [0 limit]] (set res.i (f i1.i))) + 2 (loop [i :range [0 limit]] (set res.i (f i1.i i2.i))) + 3 (loop [i :range [0 limit]] (set res.i (f i1.i i2.i i3.i))) + 4 (loop [i :range [0 limit]] (set res.i (f i1.i i2.i i3.i i4.i))) (loop [i :range [0 limit]] (def args (array/new ninds)) - (loop [j :range [0 ninds]] (:= args.j inds.j.i)) - (:= res.i (f ;args)))) + (loop [j :range [0 ninds]] (set args.j inds.j.i)) + (set res.i (f ;args)))) res) (defn mapcat @@ -691,7 +691,7 @@ (var going true) (while (if (< i len) going) (def item ind.i) - (if (pred item) (:= going false) (++ i))) + (if (pred item) (set going false) (++ i))) (if going nil i)) (defn find @@ -784,7 +784,7 @@ [ind] (var res true) (loop [x :in ind :while res] - (if x nil (:= res x))) + (if x nil (set res x))) res) (defn reverse @@ -825,7 +825,7 @@ value, one key will be ignored." The key then, is associated to the function's return value" [coll a-key a-function & args] (def old-value coll.a-key) - (:= coll.a-key (a-function old-value ;args))) + (set coll.a-key (a-function old-value ;args))) (defn merge-into "Merges multiple tables/structs into a table. If a key appears in more than one @@ -834,7 +834,7 @@ value, one key will be ignored." [tab & colls] (loop [c :in colls key :keys c] - (:= tab.key c.key)) + (set tab.key c.key)) tab) (defn merge @@ -845,7 +845,7 @@ value, one key will be ignored." (def container @{}) (loop [c :in colls key :keys c] - (:= container.key c.key)) + (set container.key c.key)) container) (defn keys @@ -855,7 +855,7 @@ value, one key will be ignored." (var k (next x nil)) (while (not= nil k) (array/push arr k) - (:= k (next x k))) + (set k (next x k))) arr) (defn values @@ -865,7 +865,7 @@ value, one key will be ignored." (var k (next x nil)) (while (not= nil k) (array/push arr x.k) - (:= k (next x k))) + (set k (next x k))) arr) (defn pairs @@ -875,7 +875,7 @@ value, one key will be ignored." (var k (next x nil)) (while (not= nil k) (array/push arr (tuple k x.k)) - (:= k (next x k))) + (set k (next x k))) arr) (defn frequencies @@ -885,7 +885,7 @@ value, one key will be ignored." (loop [x :in ind] (def n freqs.x) - (:= freqs.x (if n (+ 1 n) 1))) + (set freqs.x (if n (+ 1 n) 1))) freqs) (defn interleave @@ -906,7 +906,7 @@ value, one key will be ignored." [xs] (def ret @[]) (def seen @{}) - (loop [x :in xs] (if seen.x nil (do (:= seen.x true) (array/push ret x)))) + (loop [x :in xs] (if seen.x nil (do (set seen.x true) (array/push ret x)))) ret) (defn flatten-into @@ -939,7 +939,7 @@ value, one key will be ignored." [sep ind] (def len (length ind)) (def ret (array/new (- (* 2 len) 1))) - (if (> len 0) (:= ret.0 ind.0)) + (if (> len 0) (set ret.0 ind.0)) (var i 1) (while (< i len) (array/push ret sep ind.i) @@ -991,7 +991,7 @@ value, one key will be ignored." $dict expr ~(if (dictionary? ,$dict) ,((fn aux [] - (:= key (next pattern key)) + (set key (next pattern key)) (if (= key nil) (onmatch) (match-1 (get pattern key) (tuple get $dict key) aux seen)))) @@ -1049,7 +1049,7 @@ value, one key will be ignored." (def oldcur current) (def spacer (if (<= maxcol (+ current (length word) 1)) - (do (:= current 0) "\n ") + (do (set current 0) "\n ") (do (++ current) " "))) (+= current (length word)) (if (> oldcur 0) @@ -1066,7 +1066,7 @@ value, one key will be ignored." (if (> (length word) 0) (pushword)) (when (= b 10) (buffer/push-string buf "\n ") - (:= current 0))))) + (set current 0))))) # Last word (pushword) @@ -1103,7 +1103,7 @@ value, one key will be ignored." (var key (next t nil)) (while (not= nil key) (put newt (macex1 key) (on-value t.key)) - (:= key (next t key))) + (set key (next t key))) newt) (defn expand-bindings [x] @@ -1151,7 +1151,7 @@ value, one key will be ignored." (tuple t.0 (qq t.1))) (def specs - {':= expanddef + {'set expanddef 'def expanddef 'do expandall 'fn expandfn @@ -1185,14 +1185,14 @@ value, one key will be ignored." [pred xs] "Returns true if all xs are truthy, otherwise the first false or nil value." (var ret true) - (loop [x :in xs :while ret] (:= ret (pred x))) + (loop [x :in xs :while ret] (set ret (pred x))) ret) (defn some [pred xs] "Returns false if all xs are false or nil, otherwise returns the first true value." (var ret nil) - (loop [x :in xs :while (not ret)] (if-let [y (pred x)] (:= ret y))) + (loop [x :in xs :while (not ret)] (if-let [y (pred x)] (set ret y))) ret) (defn deep-not= @@ -1225,8 +1225,8 @@ value, one key will be ignored." (while (deep-not= current previous) (if (> (++ counter) 200) (error "macro expansion too nested")) - (:= previous current) - (:= current (macex1 current))) + (set previous current) + (set current (macex1 current))) current) ### @@ -1274,7 +1274,7 @@ value, one key will be ignored." (if (= (type res) :function) (res) (do - (:= good false) + (set good false) (def {:error err :start start :end end :fiber errf} res) (onstatus :compile @@ -1289,7 +1289,7 @@ value, one key will be ignored." (if going (onstatus (fiber/status f) res f where)))) (def oldenv *env*) - (:= *env* env) + (set *env* env) # Run loop (def buf @"") @@ -1299,10 +1299,10 @@ value, one key will be ignored." (var pindex 0) (var pstatus nil) (def len (length buf)) - (if (= len 0) (:= going false)) + (if (= len 0) (set going false)) (while (> len pindex) (+= pindex (parser/consume p buf pindex)) - (while (= (:= pstatus (parser/status p)) :full) + (while (= (set pstatus (parser/status p)) :full) (eval1 (parser/produce p))) (when (= pstatus :error) (onstatus :parse @@ -1311,7 +1311,7 @@ value, one key will be ignored." nil where)))) - (:= *env* oldenv) + (set *env* oldenv) env) @@ -1369,7 +1369,7 @@ value, one key will be ignored." (var state (string str)) (defn chunks [buf _] (def ret state) - (:= state nil) + (set state nil) (when ret (buffer/push-string buf str) (buffer/push-string buf "\n"))) @@ -1377,7 +1377,7 @@ value, one key will be ignored." (run-context *env* chunks (fn [sig x f source] (if (= sig :dead) - (:= returnval x) + (set returnval x) (status-pp sig x f source))) "eval") returnval) @@ -1470,8 +1470,8 @@ value, one key will be ignored." check (do (def newenv (make-env)) - (:= cache.path newenv) - (:= loading.path true) + (set cache.path newenv) + (set loading.path true) (def f (find-mod path)) (if f (do @@ -1490,7 +1490,7 @@ value, one key will be ignored." (if (not n) (error (string "could not open file for module " path))) ((native n) newenv))) - (:= loading.path false) + (set loading.path false) newenv))))) (defn import* @@ -1510,7 +1510,7 @@ value, one key will be ignored." (when (not v:private) (def newv (table/setproto @{:private true} v)) (put env (symbol prefix k) newv)) - (:= k (next newenv k)))) + (set k (next newenv k)))) (defmacro import "Import a module. First requires the module, and then merges its @@ -1547,9 +1547,9 @@ value, one key will be ignored." [env &] (default env *env*) (def envs @[]) - (do (var e env) (while e (array/push envs e) (:= e (table/getproto e)))) + (do (var e env) (while e (array/push envs e) (set e (table/getproto e)))) (def symbol-set @{}) (loop [envi :in envs k :keys envi] - (:= symbol-set.k true)) + (set symbol-set.k true)) (sort (keys symbol-set))) diff --git a/src/core/specials.c b/src/core/specials.c index ab7b56ad..3b32484d 100644 --- a/src/core/specials.c +++ b/src/core/specials.c @@ -648,16 +648,15 @@ error2: /* Keep in lexicographic order */ static const JanetSpecial janetc_specials[] = { - {":=", janetc_varset}, {"def", janetc_def}, {"do", janetc_do}, {"fn", janetc_fn}, {"if", janetc_if}, {"quasiquote", janetc_quasiquote}, {"quote", janetc_quote}, + {"set", janetc_varset}, {"splice", janetc_splice}, {"unquote", janetc_unquote}, - {"unquote", janetc_unquote}, {"var", janetc_var}, {"while", janetc_while} }; diff --git a/src/mainclient/init.janet b/src/mainclient/init.janet index 5ac289eb..25ee876c 100644 --- a/src/mainclient/init.janet +++ b/src/mainclient/init.janet @@ -24,12 +24,12 @@ (os/exit 0) 1) "v" (fn [&] (print janet/version "-" janet/build) (os/exit 0) 1) - "s" (fn [&] (:= *raw-stdin* true) (:= *should-repl* true) 1) - "r" (fn [&] (:= *should-repl* true) 1) - "p" (fn [&] (:= *exit-on-error* false) 1) - "-" (fn [&] (:= *handleopts* false) 1) + "s" (fn [&] (set *raw-stdin* true) (set *should-repl* true) 1) + "r" (fn [&] (set *should-repl* true) 1) + "p" (fn [&] (set *exit-on-error* false) 1) + "-" (fn [&] (set *handleopts* false) 1) "e" (fn [i &] - (:= *no-file* false) + (set *no-file* false) (eval (get process/args (+ i 1))) 2)}) @@ -45,7 +45,7 @@ (if (and *handleopts* (= "-" (string/slice arg 0 1))) (+= i (dohandler (string/slice arg 1 2) i)) (do - (:= *no-file* false) + (set *no-file* false) (import* _env arg :prefix "" :exit *exit-on-error*) (++ i)))) diff --git a/test/helper.janet b/test/helper.janet index f0478341..2f02847e 100644 --- a/test/helper.janet +++ b/test/helper.janet @@ -13,7 +13,7 @@ x) (defn start-suite [x] - (:= suite-num x) + (set suite-num x) (print "\nRunning test suite " x " tests...\n")) (defn end-suite [] diff --git a/test/suite0.janet b/test/suite0.janet index 957629f5..ef9e3480 100644 --- a/test/suite0.janet +++ b/test/suite0.janet @@ -80,7 +80,7 @@ # Mcarthy's 91 function (var f91 nil) -(:= f91 (fn [n] (if (> n 100) (- n 10) (f91 (f91 (+ n 11)))))) +(set f91 (fn [n] (if (> n 100) (- n 10) (f91 (f91 (+ n 11)))))) (assert (= 91 (f91 10)) "f91(10) = 91") (assert (= 91 (f91 11)) "f91(11) = 91") (assert (= 91 (f91 20)) "f91(20) = 91") @@ -92,7 +92,7 @@ (assert (= 94 (f91 104)) "f91(104) = 94") # Fibonacci -(def fib (do (var fib nil) (:= fib (fn [n] (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))))) +(def fib (do (var fib nil) (set fib (fn [n] (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))))) (def fib2 (fn fib2 [n] (if (< n 2) n (+ (fib2 (- n 1)) (fib2 (- n 2)))))) (assert (= (fib 0) (fib2 0) 0) "fib(0)") @@ -127,15 +127,15 @@ (var accum 1) (var count 0) (while (< count 16) - (:= accum (<< accum 1)) - (:= count (+ 1 count))) + (set accum (<< accum 1)) + (set count (+ 1 count))) (assert (= accum 65536) "loop in closure"))) (var accum 1) (var count 0) (while (< count 16) - (:= accum (<< accum 1)) - (:= count (+ 1 count))) + (set accum (<< accum 1)) + (set count (+ 1 count))) (assert (= accum 65536) "loop globally") (assert (= (struct 1 2 3 4 5 6 7 8) (struct 7 8 5 6 3 4 1 2)) "struct order does not matter 1") @@ -228,18 +228,18 @@ (def xi (get xs i)) (def yj (get ys j)) (if (< xi yj) - (do (array/push ret xi) (:= i (+ i 1))) - (do (array/push ret yj) (:= j (+ j 1))))) + (do (array/push ret xi) (set i (+ i 1))) + (do (array/push ret yj) (set j (+ j 1))))) # Push rest of xs (while (< i xlen) (def xi (get xs i)) (array/push ret xi) - (:= i (+ i 1))) + (set i (+ i 1))) # Push rest of ys (while (< j ylen) (def yj (get ys j)) (array/push ret yj) - (:= j (+ j 1))) + (set j (+ j 1))) ret) (assert (apply <= (merge @[1 3 5] @[2 4 6])) "merge sort merge 1") @@ -255,7 +255,7 @@ (var count 0) (while (< count 128) (put syms (gensym) true) - (:= count (+ 1 count))) + (set count (+ 1 count))) (assert (= (length syms) 128) "many symbols"))) # Let diff --git a/test/suite1.janet b/test/suite1.janet index 43228445..39f6d207 100644 --- a/test/suite1.janet +++ b/test/suite1.janet @@ -33,7 +33,7 @@ (defn myfun [x] (var a 10) - (:= a (do + (set a (do (def y x) (if x 8 9)))) @@ -44,7 +44,7 @@ (var good true) (loop [i :range [0 n]] (if (not (f)) - (:= good false))) + (set good false))) (assert good e)) (assert-many (fn [] (>= 1 (math/random) 0)) 200 "(random) between 0 and 1")