Re: Joy of Clojure question

2014-05-14 Thread kurofune
Haha, right on Gary! I used the later version of the original function, but the earlier call to the original function. Here is what it looked like in the beginning. This was an example of how not to write a function that looks up indices by value. The example code I posted above was the suppos

Re: Joy of Clojure question

2014-05-14 Thread Gary Johnson
Bridget and Guru are both right about the reason that \3 is found at position 13 in the string. However, the code you typed isn't valid Clojure, since the pos function expects pred to be a function of v. Thus, your pos call would need to look like this: (pos #(= % \3) ":a 4 :b 1 :c 3 :d 4") =>

Re: Joy of Clojure question

2014-05-13 Thread gamma235
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

Re: Joy of Clojure question

2014-05-13 Thread Guru Devanla
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

Re: Joy of Clojure question

2014-05-13 Thread Bridget
\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 rea