On Oct 3, 8:01 am, Stuart Halloway <[EMAIL PROTECTED]> wrote:
> I was surprised to find out that contains? checks keys, even on
> vectors. Is this idiomatic in some language? I think most new users to
> Clojure will find it confusing.
>
> I propose that contains? checks values on vectors, leaving the
> behavior as-is for other collection types.
>
> And yes, I understand the existing behavior is consistent (at the data
> structure level). But it doesn't meet user expectations.
>

contains? is about associative things, and should remain so. It's a
powerful aspect of Clojure that you can take code that uses maps and
swap in vectors and vice-versa. Clojure is also generally careful not
to mix performance models, and contains? carries a better-than-linear
perf expectation. So, I'd prefer it not be semantically overloaded.

There have been requests for find in vector, and find in sequence,
which would be useful.

In particular, they are much more useful if they don't simply return a
boolean answer, which contains? does because the things it works on
are key based.

Possible models are CL's member, which works on lists and returns the
tail beginning with the found item, and position, which works on
sequences and returns the index if found. There are also versions of
each that use predicate functions.

http://www.lispworks.com/documentation/HyperSpec/Body/f_mem_m.htm
http://www.lispworks.com/documentation/HyperSpec/Body/f_pos_p.htm

I'm open to variants of either or both of these, and have left the
names open looking forward to supporting them eventually. My
inclination is that position in Clojure should work only on indexed
things - vectors and arrays.

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

Reply via email to