I see, so you wanted to allow some subset of the optional arguments. Might I recommend the following? Sets are already functions that check for inclusion of the objects on which you call them, so instead of (contains? some-set ele) just (some-set ele) will work. Also, upon actually making a typo you just get the statement that (contains? #{:a :b} each) has failed, while I think it would be nicer if it actually showed the offending misspelled keyword. Unfortunately implementing this proved harder than I expected and the best I could come up with was:
(defn hello [& {:keys [a b] :as input}] (dorun (map #(eval `(assert (#{:a :b} (quote ~%)))) (keys input))) "hello") I'd be curious what the right way to to this is. sincerely, --Robert McIntyre On Sat, Jan 29, 2011 at 4:15 PM, Shantanu Kumar <kumar.shant...@gmail.com> wrote: > > On Jan 30, 1:26 am, Robert McIntyre <r...@mit.edu> wrote: >> you could do something like this, but I'm curious --- why do you want >> to restrict the function's inputs in this way? > > As they are optional arguments, it's possible that somebody might > misspell a key and spend time debugging. The intention is to avoid > that. > >> >> (defn hello [& {:keys [a b] :as input}] >> (assert (= (set (keys input)) #{:a :b})) >> "hello") > > Thanks, I realized I need something like the following: > > (defn hello > [& {:keys [a b] :as input}] > (doseq [each (keys input)] > (assert (contains? #{:a :b} each))) > "hello") > > Regards, > Shantanu > > -- > 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