mirror of
https://github.com/janet-lang/janet
synced 2025-06-11 02:54:12 +00:00
Fix if-let when-let and add put-in (assoc-in)
This commit is contained in:
parent
3c57980ef1
commit
1bc5705667
@ -367,13 +367,16 @@ If no match is found, returns nil"
|
|||||||
(tuple 'when (tuple not condition) exp-1))
|
(tuple 'when (tuple not condition) exp-1))
|
||||||
|
|
||||||
(defmacro if-let
|
(defmacro if-let
|
||||||
"Takes the first one or two forms in a vector and if true binds
|
"Takes the first one or two forms in a vector and if both are true binds
|
||||||
all the forms with let and evaluates the first expression else
|
all the forms with let and evaluates the first expression else
|
||||||
evaluates the second"
|
evaluates the second"
|
||||||
[bindings then else]
|
[bindings then else]
|
||||||
(def head (ast-unwrap1 bindings))
|
#(tuple 'print (tuple '> (tuple 'length bindings) 2))
|
||||||
(tuple 'let head
|
(tuple 'let bindings
|
||||||
(tuple 'if (and (get head 1) (if (get head 2) (get head 3) true))
|
(tuple 'if (tuple 'and (tuple 'get bindings 1)
|
||||||
|
(tuple 'if
|
||||||
|
(tuple '> (tuple 'length bindings) 2)
|
||||||
|
(tuple 'get bindings 3) 'true))
|
||||||
then
|
then
|
||||||
else)))
|
else)))
|
||||||
|
|
||||||
@ -385,7 +388,10 @@ If no match is found, returns nil"
|
|||||||
(tuple 'let head
|
(tuple 'let head
|
||||||
(tuple
|
(tuple
|
||||||
'when
|
'when
|
||||||
(and (get head 1) (if (get head 2) (get head 3) true))
|
(tuple 'and (tuple 'get bindings 1)
|
||||||
|
(tuple 'if
|
||||||
|
(tuple '> (tuple 'length bindings) 2)
|
||||||
|
(tuple 'get bindings 3) 'true))
|
||||||
(apply1 tuple (array-concat ['do] (ast-unwrap1 body))))))
|
(apply1 tuple (array-concat ['do] (ast-unwrap1 body))))))
|
||||||
|
|
||||||
(defn comp
|
(defn comp
|
||||||
|
Loading…
x
Reference in New Issue
Block a user