Okay, both these answers make lots of sense. thank you for your help. 

J

On Wednesday, May 14, 2014 11:47:51 AM UTC+9, Guru Devanla wrote:
>
> The call to (index) returns this vector 
>
> ([0 \:] [1 \a] [2 \space] [3 \4] [4 \space] [5 \:] [6 \b] [7 \space] [8 
> \1] [9 \space] [10 \:] [11 \c] [12 \space] [13 \3] [14 \space] [15 \:] [16 
> \d] [17 \space] [18 \4])
>
> And, 3 here is in the 13th position. Your (cond) in index function is 
> picking up the :else branch.
>
>
> On Tue, May 13, 2014 at 6:44 PM, gamma235 <jesus.d...@gmail.com<javascript:>
> > 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 clo...@googlegroups.com<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> 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+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

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

Reply via email to