\3 is a character literal, so you're looking up the character 3. You're looking it up in a collection which is a string. Count from the first position, 0, a colon, then 1, the letter a, and so on. 3 is at the 13th position.
On Tuesday, May 13, 2014 9:44:38 PM UTC-4, gamma235 wrote: > > I am reading The Joy of Clojure now and am finishing chapter 5 on sequence > abstractions. There is an example given that demonstrates how to locate the > index of an element in a sequence by value, but I don't understand why the > character lookup here is returning 13. Can somebody please explain this to > me? > > (defn index [coll] >> (cond >> (map? coll) (seq coll) >> (set? coll) (map vector coll coll) >> :else (map vector (iterate inc 0) coll))) >> >> (defn pos [pred coll] >> (for [[i v] (index coll) :when (pred v)] i)) >> > > >> (pos \3 ":a 4 :b 1 :c 3 :d 4") > > > > => 13 > > > J > -- 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 --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.