I got it, Think you very much!
在 2014年2月4日星期二UTC+8上午2时01分50秒,Justin Smith写道:
>
> if pred is false or nil (the two cases "when" would rule out), it would be
> an error to apply it to an argument
>
> #{\a \b} is a literal set syntax, containing keys \a and \b. {\a \b} is a
> literal hash-map synta
if pred is false or nil (the two cases "when" would rule out), it would be
an error to apply it to an argument
#{\a \b} is a literal set syntax, containing keys \a and \b. {\a \b} is a
literal hash-map syntax, with one key \a mapped to the value \b. As far as
index-filter is concerned, it only
a vector is a function of its indices
a map is a function of its keys
a set is a function of its elements
does this help at all?
Jim
On 03/02/14 15:29, action wrote:
(defn index-filter [pred coll]
(when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))
(index-filter #{\a \b
(defn index-filter [pred coll]
(when pred
(for [[idx elt] (indexed coll) :when (pred elt)] idx)))
(index-filter #{\a \b} "abcdef")
-> (0 1)
but I don't know why use "when pred" in the code,
and why "(index-filter {\a \b} "abcdef")" doesn't work?
--
You received this message because you