1
0
mirror of https://github.com/janet-lang/janet synced 2024-12-23 15:00:27 +00:00

Replace varset! with algol style :=

This commit is contained in:
Calvin Rose 2018-03-16 18:15:34 -04:00
parent f5213e4064
commit 4a76f2ae32
6 changed files with 27 additions and 22 deletions

View File

@ -18,6 +18,10 @@ Implemented in mostly standard C99, dst runs on Windows, Linux and macOS.
The few features that are not standard C (dynamic library loading, compiler specific optimizations),
are fairly straight forward. Dst can be easily ported to new platforms.
There is not much in the way of documentation yet because it is still a "personal project" and
I don't want to freeze features prematurely. You can look in the examples directory, the test directory,
or the file `src/compiler/boot.dst` to get a sense of what dst code looks like.
## Features
* First class closures

View File

@ -11,10 +11,11 @@
state
(do
(def n (f))
(varset! state n)
(varset! loaded true)
(:= state n)
(:= loaded true)
n))))
# This creates one more closure than necessary but oh well
(defmacro delay
"Macro for lazy evaluation"
[& forms] (tuple mem0 (apply1 tuple (array-concat ['fn []] forms))))

View File

@ -139,7 +139,7 @@ If no match is found, returns nil"
:more (fn [] (< i len))
:next (fn []
(def ret (get x i))
(varset! i (+ i 1))
(:= i (+ i 1))
ret)
})
(def iters {
@ -156,7 +156,7 @@ If no match is found, returns nil"
:more (fn [] (< i top))
:next (fn []
(def ret i)
(varset! i (+ i 1))
(:= i (+ i 1))
ret)
})
@ -199,9 +199,9 @@ If no match is found, returns nil"
(do
(def n (next))
(if (pred n) n (nextgood)))
(varset! alive false))))
(defn nnext [] (def ret temp) (varset! temp (nextgood)) ret)
(defn nmore [] (when isnew (varset! isnew false) (nnext)) alive)
(:= alive false))))
(defn nnext [] (def ret temp) (:= temp (nextgood)) ret)
(defn nmore [] (when isnew (:= isnew false) (nnext)) alive)
{:more nmore :next nnext})
(defmacro let [bindings & body]
@ -213,7 +213,7 @@ If no match is found, returns nil"
(array-push accum (tuple 'def
(get head i)
(get head (+ 1 i))))
(varset! i (+ i 2)))
(:= i (+ i 2)))
(array-push accum (tuple-prepend body 'do))
(apply1 tuple accum))
@ -223,7 +223,7 @@ If no match is found, returns nil"
:more (fn [] lastkey)
:next (fn []
(def ret (tuple lastkey (get x lastkey)))
(varset! lastkey (next x lastkey))
(:= lastkey (next x lastkey))
ret)
})
@ -233,7 +233,7 @@ If no match is found, returns nil"
:more (fn [] lastkey)
:next (fn []
(def ret lastkey)
(varset! lastkey (next x lastkey))
(:= lastkey (next x lastkey))
ret)
})
@ -243,7 +243,7 @@ If no match is found, returns nil"
:more (fn [] lastkey)
:next (fn []
(def ret (get x lastkey))
(varset! lastkey (next x lastkey))
(:= lastkey (next x lastkey))
ret)
})
@ -260,7 +260,7 @@ If no match is found, returns nil"
(tuple 'def endsym end)
(tuple 'while (tuple '< sym endsym)
(tuple-prepend body 'do)
(tuple 'varset! sym (tuple '+ sym inc)))))
(tuple ':= sym (tuple '+ sym inc)))))
(defmacro ->
[x & forms]
@ -311,7 +311,7 @@ If no match is found, returns nil"
(pp seen buf k)
(buffer-push-string buf " ")
(pp seen buf v)
(varset! k (next a k))
(:= k (next a k))
(when k (buffer-push-string buf " ")))
(buffer-push-string buf end)))
buf)
@ -369,7 +369,7 @@ onvalue."
(while (< 0 len)
(buffer-clear buf)
(chunks buf)
(varset! len (length buf))
(:= len (length buf))
(for [i 0 len]
(yield (get buf i))))
0)))
@ -385,17 +385,17 @@ onvalue."
(select (fiber-status chars)
:new (parser-byte p (resume chars))
:pending (parser-byte p (resume chars))
(varset! going false))))
(:= going false))))
(when (not= :root (parser-status p))
(onerr "parse" "unexpected end of source"))
nil)))
(defn more [] (if temp true
(do
(varset! temp true)
(varset! tempval (resume f))
(:= temp true)
(:= tempval (resume f))
going)))
(defn next [] (if temp
(do (varset! temp nil) tempval)
(do (:= temp nil) tempval)
(resume f)))
{:more more :next next})
(fn [env chunks onvalue onerr]

View File

@ -615,6 +615,7 @@ DstSlot dstc_fn(DstFopts opts, DstAst *ast, int32_t argn, const Dst *argv) {
/* Keep in lexographic order */
static const DstSpecial dstc_specials[] = {
{":=", dstc_varset},
{"ast-quote", dstc_astquote},
{"def", dstc_def},
{"do", dstc_do},
@ -622,7 +623,6 @@ static const DstSpecial dstc_specials[] = {
{"if", dstc_if},
{"quote", dstc_quote},
{"var", dstc_var},
{"varset!", dstc_varset},
{"while", dstc_while}
};

View File

@ -136,7 +136,7 @@ int dst_core_struct(DstArgs args) {
int dst_core_fiber(DstArgs args) {
DstFiber *fiber;
if (args.n < 1) return dst_throw(args, "expected at least one argument");
if (args.n < 1) return dst_throw(args, "expected at least 1 argument");
if (!dst_checktype(args.v[0], DST_FUNCTION))
return dst_throw(args, "expected a function");
fiber = dst_fiber(dst_unwrap_function(args.v[0]), 64);

View File

@ -13,7 +13,7 @@
(print " -r Enter the repl after running all scripts")
(exit 0))
"v" (fn [] (print VERSION) (exit 0))
"r" (fn [] (varset! should-repl true))
"r" (fn [] (:= should-repl true))
})
(defn dohandler [n]
@ -27,7 +27,7 @@
(if (= "-" (string-slice arg 0 1))
(dohandler (string-slice arg 1 2))
(do
(varset! no-file false)
(:= no-file false)
(import arg))))
(when (or should-repl no-file)