Tangent:

On Fri, Apr 16, 2010 at 7:41 PM, Douglas Philips <d...@mac.com> wrote:
> (1) http://clojure.org/data_structures says:
> ... seq returns a sequence of map entries, which are key/value pairs. ...
>
> I haven't yet found where in the docs a pair is defined, so I am guessing
> that the concrete type (list, vector,...) for a pair is not
> relevant/important.

That's right. But what is surprising is that when you try to go in the
other direction by converting a sequence of two-element sequences into
a map then the concrete type of those two-element sequences matters a
great deal:

user> (conj {} [:foo 1])
{:foo 1}
user> (conj {} (list :foo 1))
; Evaluation aborted.

What's happening is that APersistentMap.cons() has a hard-coded type
check for IPersistentVector. There doesn't seem to be any good for why
it shouldn't work with any ISeq. Maybe performance? If that is a valid
concern, you could retain the current branch for IPersistentVector and
append an else-if for ISeqs.

This isn't a big problem in practice, though I've been bitten by it
unexpectedly once or twice. But it's a surprising violation of the
principle that one kind of sequence should be as good as any other
when the context calls for no particular performance characteristics
(e.g. O(1) random access).

-Per

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