mirror of
https://github.com/janet-lang/janet
synced 2024-11-28 11:09:54 +00:00
Add label macro.
A lexically scoped version of prompt is often useful.
This commit is contained in:
parent
59d288c429
commit
05bd5767de
@ -300,7 +300,7 @@
|
|||||||
(propagate ,r ,f)))))
|
(propagate ,r ,f)))))
|
||||||
|
|
||||||
(defmacro prompt
|
(defmacro prompt
|
||||||
"Set up a prompt point that can be aborted to. Tag should be a value
|
"Set up a checkpoint that can be returned to. Tag should be a value
|
||||||
that is used in a return statement, like a keyword."
|
that is used in a return statement, like a keyword."
|
||||||
[tag & body]
|
[tag & body]
|
||||||
(with-syms [res target payload fib]
|
(with-syms [res target payload fib]
|
||||||
@ -312,9 +312,17 @@
|
|||||||
,payload
|
,payload
|
||||||
(propagate ,res ,fib)))))
|
(propagate ,res ,fib)))))
|
||||||
|
|
||||||
|
(defmacro label
|
||||||
|
"Set a label point that is lexically scoped. Name should be a symbol
|
||||||
|
that will be bound to the label."
|
||||||
|
[name & body]
|
||||||
|
~(do
|
||||||
|
(def ,name ',(gensym))
|
||||||
|
,(apply prompt name body)))
|
||||||
|
|
||||||
(defn return
|
(defn return
|
||||||
"Return to a prompt point."
|
"Return to a prompt point."
|
||||||
[to value]
|
[to &opt value]
|
||||||
(signal 0 [to value]))
|
(signal 0 [to value]))
|
||||||
|
|
||||||
(defmacro with
|
(defmacro with
|
||||||
|
Loading…
Reference in New Issue
Block a user