You can use the :pre and :post assertions on functions. Something like the following would do what you are asking:
(defn myfun [& {:keys [arg1 arg2 arg3] :or {arg1 "default-value"} :as args}] {:pre [(every? #{:arg1 :arg2 :arg3} (keys args))]} (println arg1 arg2 arg3 "args:" args)) Also, another way to take keyword arguments is: (defn foo [& opts] (let [opts (apply hash-map opts)] (println opts))) - Mark On Sun, Nov 27, 2011 at 5:57 AM, Razvan Rotaru <razvan.rot...@gmail.com> wrote: > Hi, > > This may be a question without hope, but I'm thinking that asking > never hurts. So here goes: > > The closest thing to keyword arguments that I have found is > destructuring with a map: > > (defn myfun [& {:keys [arg1 arg2 arg3] > :or {arg1 "default-value"} :as args}] > ...) > > When I call myfun without specifying value for arg2 or arg3 I get an > error, which is great. However, when I do this: > > (myfun :arg2 2 :arg3 3 :arg15 15) > > I don't get an error, because of the rest (&) thing. Do you know if > this can be achieved with a nice syntax, and not check args in the > code (i.e. checking should be done when evaluating/creating the > function, and not when executing). > > Thanks, > Razvan > > -- > You received this message because you are subscribed to the Google > Groups "Clojure" group. > To post to this group, send email to clojure@googlegroups.com > Note that posts from new members are moderated - please be patient with your > first post. > To unsubscribe from this group, send email to > clojure+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/clojure?hl=en -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en