Created
August 26, 2011 18:24
-
-
Save nipra/1174053 to your computer and use it in GitHub Desktop.
Python **kwargs like functionality when doing function call
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Just for fun! | |
;; If Clojure were like Python, I could have used (asdf **{:a 1 :b 2 :c 3}) when calling asdf | |
user> (defn asdf | |
[& {:keys [a b c]}] | |
[a b c]) | |
#'user/asdf | |
user> (defmacro call** | |
[func kw-map] | |
`(~func ~@(mapcat identity kw-map))) | |
#'user/call** | |
user> (call** asdf {:a 1 :b 2 :c 3}) | |
[1 2 3] | |
user> (macroexpand '(call** asdf {:a 1 :b 2 :c 3})) | |
(asdf :a 1 :b 2 :c 3) | |
user> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
IMHO, @ghoseb's version is more idiomatic.