-
-
Save aria42/3814548 to your computer and use it in GitHub Desktop.
Bring on the fnk
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
(defnk foo [x y [s 1]] | |
(+ x (* y s))) | |
(foo {:x 2 :y 3 :s 2}) | |
;; ==> 8 | |
(foo {:x 2 :y 3}) | |
;; 's' defaulted to 1 | |
;; ==> 5 | |
(foo {:x 2}) | |
;; ==> (Exception. "Missing argument :y calling foo (got #{:x})") | |
(meta foo) | |
;; ==> {:req-ks #{:x :y}} | |
;; :opt-ks #{:s} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment