Yeah, laziness on my part, I was just trying to show that everything
after '&' comes in as a list, and you can be creative if you need to
be. I use this on occasion for macros with multiple different types
of optional arguments.
On Sun, Nov 27, 2011 at 6:45 PM, Alan Malloy wrote:
> On Nov 27, 8:
On Nov 27, 8:43 am, Mark Rathwell wrote:
> Also, another way to take keyword arguments is:
>
> (defn foo [& opts]
> (let [opts (apply hash-map opts)]
> (println opts)))
This is what already happens internally with the & {:keys ...}
notation. You can actually be rather more concise if you wr
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,
I found it hard to figure out how best to get common lisp-style keyword
arguments with defaults, and had been doing it in a clunky way until Chas
showed me the way I show below. Now I've had a student also fail to figure it
out until I showed him, and it occurred to me that maybe I should sugge