How to use named parameters in ClojureScript?

In clojure, I can use defnk to get named parameters. How can I achieve the same in ClojureScript?

+4
source share
1 answer

The named args function in ClojureScript is the same as in Clojure:

(defn f [x & {:keys [ab]}] (println (str "a is " a " and b is " b))) (f 1) ; a is and b is (f 1 :a 42) ; a is 42 and b is (f 1 :a 42 :b 108) ; a is 42 and b is 108 

If you want the default values, change the original to:

 (defn f [x & {:keys [ab] :or {a 999 b 9}}] (println (str "a is " a " and b is " b))) (f 1) ; a is 999 and b is 9 

This is due to the good answer to Clojure - named arguments

+10
source

Source: https://habr.com/ru/post/1389051/


All Articles