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"
|
||||
(let [[-fun (car call)]
|
||||
[-args (cdr call)]
|
||||
[-okwargs kwargs]]
|
||||
[-okwargs `[(list (.items ~kwargs))]]]
|
||||
(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 -args (cdr (car -args))))
|
||||
|
||||
`(apply ~-fun [~@-args] ~-okwargs)))
|
||||
`(apply ~-fun [~@-args] (dict (sum ~-okwargs [])))))
|
||||
|
@ -154,13 +154,15 @@
|
||||
(assert (= (kwapply (kwtest) mydict) mydict))
|
||||
(assert (= (kwapply (kwtest) ((fn [] {"one" "two"}))) {"one" "two"}))
|
||||
(assert (= (kwapply
|
||||
(kwapply
|
||||
(kwapply
|
||||
(kwapply
|
||||
(kwapply (kwtest) {"x" 4})
|
||||
mydict)
|
||||
{"x" 8})
|
||||
{"x" (- 3 2) "y" 2})
|
||||
{"y" 5 "z" 3})
|
||||
{"x" 1 "y" 5 "z" 3})))
|
||||
{"x" 1 "y" 5 "z" 3 "one" "three"})))
|
||||
|
||||
(defn test-apply []
|
||||
"NATIVE: test working with args and functions"
|
||||
|
Loading…
x
Reference in New Issue
Block a user