Hi all,

I have a function 





*(defn foo [a b & {:keys [c d]                  :or {c "C" d "D"}          
        :as opt-args}]  [a b opt-args])*

I want to let users call *(foo 1 2 :e "E")* and get *[1 2 {:e "E", :c "C", 
:d "D"}]*. But *:or* only affects the binding of *c* and *d* - not 
*opt-args*. So you get *[1 2 {:e "E"}]*.

So I use merge:

(defn foo [a b & {:keys [c d]
                  :or {c "C" d "D"}
                  :as opt-args}]
  (let [opt-args (merge {:c c :d d} opt-args)]
    [a b opt-args]))

So what about introducing destructuring with *:merge*? Like this:

(defn foo [a b & {:merge {:c "C" :d "D"}
                  :as opt-args}]
  [a b opt-args])

In this case I don't even need bindings for c and d. But I  could imagine 
that this binding form does create those bindings. Or make it look more 
like :keys:

(defn foo [a b & {:merge {c "C" d "D"}
                  :as opt-args}]
  [a b opt-args])

Does this make sense? Is there currently a more elegant way to get this 
functionality without the merge I use?

What do you think?

- Henrik



-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to