Hi
I'm new to Clojure so thought that I would work through some basic
examples and decided upon 99 problems (http://aperiodic.net/phil/scala/
s-99/). So far I have got as far as #11 and have become a bit confused
as to why my initial solution does not work.
My test for this problem is
(deftest encodemodified-should-return-list-with-counts-when-more-than-
one
(is (= '((3,"a"),"b",(2,"c"),"a") (encodemodified ["a" "a" "a" "b"
"c" "c"
"a"]))))
My initial solution was the following
(defn pack
[col]
(partition-by identity
col))
(defn encodemodified
[col]
(map #(if (== (count %) 1) % (list (count %) (first
%)))
(pack col)))
This failed giving me the following result and unexpected actual
FAIL in (encodemodified-should-return-list-with-counts-when-more-than-
one) (core.clj:47)
expected: (= (quote ((3 "a") "b" (2 "c") "a")) (encodemodified ["a"
"a" "a" "b" "c" "c" "a"]))
actual: (not (= ((3 "a") "b" (2 "c") "a") ((3 "a") ("b") (2 "c")
("a"))))
If I change the second % in line 2 of the function to (first %), then
the test passes i.e.
(defn encodemodified
[col]
(map #(if (== (count %) 1) (first %) (list (count %) (first
%)))
(pack col)))
Could somebody explain to me why my failing function does not work and
returns the unexpected actual above. I expect I missing something
fairly basic.
Many thanks.
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en