On Wed, Apr 14, 2010 at 9:33 AM, Jeff Rose wrote:
> I recently discovered condp, which is good for doing the equivalent of
> a switch statement and more:
>
> (map
> (fn [[k v]]
>(condp = k
> :a (* 2 v)
> :b (* 3 v)))
> {:a "foo" :b "bar"})
>
for true switch statements (with c
On Apr 13, 11:34 pm, strattonbrazil wrote:
> I want to map a dictionary and do different things depending on the
> key. I was planning on using an if-clause, but I'm not sure how to
> compare symbols to strings.
>
> Something like
>
> (map (fn [k v] (if (== k "hello") ... ...) {:hello 1 :goodbye
> You do mean keywords rather than symbols, right? A symbol would be
> 'hello. A keyword is :hello.
> The ruby name for the clojure keyword concept is "symbol". I used to
> get the terminology backwards because of that.
>
> (assert (= (name :hello) "hello"))
> (assert (= :hello (keyword "hello")))
You do mean keywords rather than symbols, right? A symbol would be
'hello. A keyword is :hello.
The ruby name for the clojure keyword concept is "symbol". I used to
get the terminology backwards because of that.
(assert (= (name :hello) "hello"))
(assert (= :hello (keyword "hello")))
On Apr 13, 2
I want to map a dictionary and do different things depending on the
key. I was planning on using an if-clause, but I'm not sure how to
compare symbols to strings.
Something like
(map (fn [k v] (if (== k "hello") ... ...) {:hello 1 :goodbye 2})
How would I normally compare symbols and strings?