> if this works exactly like "indexOf" in java, then it seems like it  
> should be in the core ... but as "position", or "pos", based on your  
> description.  Why the core?  I'm mentioned this before: symmetry,  
> since nth is there.  Others would argue, "leave it out" since  
> there's a way to do it from java.  Personally, if you don't know  
> java, you ain't gonna be thinking "indexOf".


It doesn't work like indexOf. indexOf returns one index, and searches  
for a literal value. The CL equivalent is position.

I wouldn't use position/pos — those names imply (as they do in CL) a  
single position, searching from the start or end.

Stuart's index-filter returns a list:

user=> (index-filter even? [1 2 3 4 5 6])
(1 3 5)

The appropriate name as far as Common Lisp naming conventions go would  
be "positions-if" —

http://leitl.org/docs/comp/HyperSpec/Body/f_pos_p.htm#position

… that is, position finds the index of an item, position-if finds the  
index of an item matching the predicate, so positions-if should find  
all such matching indices.

I can't say I see any use for this function in my own coding style,  
but it certainly seems like a reasonable and general function to have.  
It's probably worth creating the whole bundle:

position
position-if
positions
positions-if

and maybe even the find-* friends.

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