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) =
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
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
\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
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
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