Allow calling kwapply with mixed names and dicts
This commit is contained in:
parent
83bb1513db
commit
59e51166fb
@ -122,10 +122,15 @@
|
|||||||
"Use a dictionary as keyword arguments"
|
"Use a dictionary as keyword arguments"
|
||||||
(let [[-fun (car call)]
|
(let [[-fun (car call)]
|
||||||
[-args (cdr call)]
|
[-args (cdr call)]
|
||||||
[-okwargs kwargs]]
|
[-okwargs `[(list (.items ~kwargs))]]]
|
||||||
(while (= -fun "kwapply") ;; join any further kw
|
(while (= -fun "kwapply") ;; join any further kw
|
||||||
(setv -okwargs (+ (car (cdr -args)) -okwargs))
|
(if (not (= (len -args) 2))
|
||||||
|
(macro-error
|
||||||
|
call
|
||||||
|
(.format "Trying to call nested kwapply with {0} args instead of 2"
|
||||||
|
(len -args))))
|
||||||
|
(.insert -okwargs 0 `(list (.items ~(car (cdr -args)))))
|
||||||
(setv -fun (car (car -args)))
|
(setv -fun (car (car -args)))
|
||||||
(setv -args (cdr (car -args))))
|
(setv -args (cdr (car -args))))
|
||||||
|
|
||||||
`(apply ~-fun [~@-args] ~-okwargs)))
|
`(apply ~-fun [~@-args] (dict (sum ~-okwargs [])))))
|
||||||
|
@ -153,14 +153,16 @@
|
|||||||
(setv mydict {"one" "three"})
|
(setv mydict {"one" "three"})
|
||||||
(assert (= (kwapply (kwtest) mydict) mydict))
|
(assert (= (kwapply (kwtest) mydict) mydict))
|
||||||
(assert (= (kwapply (kwtest) ((fn [] {"one" "two"}))) {"one" "two"}))
|
(assert (= (kwapply (kwtest) ((fn [] {"one" "two"}))) {"one" "two"}))
|
||||||
(assert (= (kwapply
|
(assert (= (kwapply
|
||||||
(kwapply
|
(kwapply
|
||||||
(kwapply
|
(kwapply
|
||||||
(kwapply (kwtest) {"x" 4})
|
(kwapply
|
||||||
{"x" 8})
|
(kwapply (kwtest) {"x" 4})
|
||||||
{"x" (- 3 2) "y" 2})
|
mydict)
|
||||||
|
{"x" 8})
|
||||||
|
{"x" (- 3 2) "y" 2})
|
||||||
{"y" 5 "z" 3})
|
{"y" 5 "z" 3})
|
||||||
{"x" 1 "y" 5 "z" 3})))
|
{"x" 1 "y" 5 "z" 3 "one" "three"})))
|
||||||
|
|
||||||
(defn test-apply []
|
(defn test-apply []
|
||||||
"NATIVE: test working with args and functions"
|
"NATIVE: test working with args and functions"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user