Gut gemacht! Absolutely amazing Meikel. Now get some well earned sleep.
Sean On Jun 4, 6:22 pm, Meikel Brandmeyer <m...@kotka.de> wrote: > Hi again, > > Am 05.06.2009 um 00:06 schrieb Meikel Brandmeyer: > > > The docstring is a bit contorted but I'm too sleepy now, > > to get that right... > > And of course I'm too sleepy to miss the keyword to > symbol conversion.... > > (defmacro defnk > "Define a function accepting keyword arguments. Symbols up to the > first > keyword in the parameter list are taken as positional arguments. > Then > an alternating sequence of keywords and defaults values is > expected. The > values of the keyword arguments are available in the function body by > virtue of the symbol corresponding to the keyword (cf. :keys > destructuring). > defnk accepts an optional docstring as well as an optional metadata > map." > [fn-name & fn-tail] > (let [[fn-name [args & body]] (name-with-attributes fn-name fn-tail) > [pos kw-vals] (split-with symbol? args) > syms (map #(-> % name symbol) (take-nth 2 > kw-vals)) > values (take-nth 2 (rest kw-vals)) > sym-vals (apply hash-map (interleave syms > values)) > de-map {:keys (vec syms) > :or sym-vals}] > `(defn ~fn-name > [...@pos & options#] > (let [~de-map (apply hash-map options#)] > ~...@body)))) > > Sincerely > Meikel > > smime.p7s > 5KViewDownload --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---