On Mar 15, 2011, at 5:28 PM, Christian wrote: > Secondly, what is happening inside the for structure? [idx elt] are > being bound to vector returned by indexed, but that assignment only > happens when pred == elt. Finally, we return the vector idx. Is this > correct?
[idx elt] is destructuring-bound to each element in (indexed coll), one after another, except that those elements for which (pred elt) returns false or nil are skipped (pred is being called as a function on elt, not compared to it). The result of the for loop is the sequence of values given by the expression in its body (in this case the indexes whose values in coll satisfied pred). That for loop would be equivalent to this map + filter: (map first (filter (fn [[idx elt]] (pred elt)) (indexed coll))) -- 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