merge confused me, too. I was surprised to see in the docs that its input needn't be sorted (or have anything to do with lists) . . . .or maybe it merges unsorted things however, but where's the discussion of whether the result of merging two sorted list is a sorted list? Well, it's avoided because it's for maps.
On Sat, Jan 24, 2009 at 1:13 AM, [email protected] <[email protected]>wrote: > > user=> (doc merge) > ------------------------- > clojure.core/merge > ([& maps]) > Returns a map that consists of the rest of the maps conj-ed onto > the first. If a key occurs in more than one map, the mapping from > the latter (left-to-right) will be the mapping in the result. > nil > > > According to merge's doc string it is meant to work on maps. However, > this is only part of the truth: > > user=> (merge '(1) 2) > (2 1) > > > user=> (merge [1] 2) > [1 2] > > user=> (merge #{1} 2) > #{1 2} > > Of course, the canonical example: > > user=> (merge {:name "ryan"} {:age 25}) > {:age 25, :name "ryan"} > > What's the point? Maybe the doc string should be changed to be more > general, or perhaps merge should check that it is indeed working with > maps? > > Personally, this doesn't bother me all that much. However, if people > rely on this behavior then it could be harmful if in a future version > of Clojure merge only works for maps, or if it's results change for > the other types of structures. I feel that a doc string should act as > a contract between the function and it's user (think Eiffel). I think > the contract for merge could be improved. > > -Ryan > > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---
