On Fri, Jan 29, 2010 at 9:40 AM, Chouser <chou...@gmail.com> wrote:
> On Fri, Jan 29, 2010 at 8:44 AM, Rich Hickey <richhic...@gmail.com> wrote:
>> On Fri, Jan 22, 2010 at 8:57 AM, Chouser <chou...@gmail.com> wrote:
>>> On Thu, Jan 21, 2010 at 10:11 PM, Sean Devlin <francoisdev...@gmail.com> 
>>> wrote:
>>>> Sometimes you don't want assoc-in to create a hash-map.  Sometimes you
>>>> wish it could create a sorted map.
>>>>
>>>> Just finished working on something with Alexy Khrabrov & Chouser on
>>>> IRC, and the three of us are wondering if the result might be
>>>> generally useful.
>>>>
>>>> (defn assoc-in-with
>>>>  "supply a default-map instead of a hash-map"
>>>>  [m default-map [k & ks] v]
>>>>  (if ks
>>>>    (assoc m k (assoc-in-as (get m k default-map) default-map ks v))
>>>>    (assoc m k v)))
>>>
>>> As I mentioned in IRC, this could actually be a 4-argument
>>> version of 'assoc-in' instead of a new function.  Assuming of
>>> course Rich likes the idea.
>>>
>>
>> Where would the default go? Also, need it be a map, vs anything
>> associative (e.g. a vector)?
>
> Since update-in could use this pattern as well, I don't think the
> default should go after the value (or update fn) position.
> I think where Sean put it is fine -- after the collection, before
> the vector of keys.
>

As soon as you are varidic with update-in I think you'll need new
names, i.e. can't just add another arity to assoc-in and update-in.

> I don't see why it needs to be restricted to a map -- all the
> normal assoc rules apply.
>

Right.

I wonder though, if a single default coll is sufficient. There are
potentially multiple levels to the structure, using different data
structures at each level.

Rich

-- 
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

Reply via email to