Right, but the :or could conceptually just merge the supplied map with the actual supplied argument map instead -- it's just another way it could go.
This is possibly a simpler model to manage in your head, since presumably you have some idea of how you want to call the function when you're writing it. I'm wondering why the symbol route was selected when the merge way may be more convenient, or why there's something really bad about the merge way that I'm overlooking. --Robert McIntyre On Mon, Sep 13, 2010 at 1:08 PM, Mark Nutter <manutte...@gmail.com> wrote: > On Mon, Sep 13, 2010 at 12:37 PM, Tom Hicks <hickstoh...@gmail.com> wrote: >> >> On Sep 12, 10:44 pm, Meikel Brandmeyer <m...@kotka.de> wrote: >>> >>> The default map specifies the default for the symbols which are bound, >>> not the source of the values. >>> >>> (let [{foo :some-key bar "some-other-key" :or {foo 1}} ....] ...) >> >> Sorry Meikel, I don't understand your answer. My question was why does >> the >> default map not lookup the values using the same lookup method as the >> original map (:keys, :strs, or :syms)? Why does it always assume >> symbols for keys? > > What he's saying is that the map after the :or is not doing a lookup > in the original map you're destructuring, so it's not a question of > doing the same kind of lookup or not. The map after the :or is a map > of local symbols to default values (as opposed to being a map of > keys-found-in-the-original-map to default values. > > (let [foo bar] ...) > Assigns the value of bar to the local symbol foo > > (let [{:keys [foo]} {:foo "bar"}] ...) > Assigns the string "bar" to the local symbol foo by looking up the > keyword :foo in the supplied map > > (let[{:keys [foo baz] :or {baz "quux"}} {:foo "bar"}]...) > The tricky bit: it looks up the key :foo in the supplied map, and > creates a local symbol "foo" with the value "bar". Next, it looks up > the keyword :baz (which is nil) and creates a local symbol named "baz" > that is also nil. At this point, it's done looking things up in the > supplied map. Now we're up to the :or part. For each local symbol with > a nil value, we look in the :or map to see if there's a key with the > same symbol. If there is, we use that as the value of the local symbol > instead of nil. But the point is we're looking up local symbols now, > not anything in the original map. > > Caveat: that's a high-level overview from a fairly new Clojure user > (me) who is only attempting to rephrase what he thinks he's understood > from reading the words of people who know what they're talking about. > The source code for :or destructuring may use a different process > completely, or I may have been more or less correct. I don't really > know, but if I've mangled anything I'm hopeful someone will correct > me. > > Cheers. > > -- > 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