Re: Programming clojure second Edition
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 syntax, with one key \a mapped to the value \b. As far as > index-filter is concerned, it only selects \a, since that is the only key > you can match. > > On Monday, February 3, 2014 7:57:55 AM UTC-8, Jim foo.bar wrote: >> >> 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} "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 are subscribed to the Google >> > Groups "Clojure" group. >> > To post to this group, send email to clo...@googlegroups.com >> > Note that posts from new members are moderated - please be patient >> > with your first post. >> > To unsubscribe from this group, send email to >> > clojure+u...@googlegroups.com >> > For more options, visit this group at >> > http://groups.google.com/group/clojure?hl=en >> > --- >> > You received this message because you are subscribed to the Google >> > Groups "Clojure" group. >> > To unsubscribe from this group and stop receiving emails from it, send >> > an email to clojure+u...@googlegroups.com. >> > For more options, visit https://groups.google.com/groups/opt_out. >> >> -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Programming clojure second Edition
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 selects \a, since that is the only key you can match. On Monday, February 3, 2014 7:57:55 AM UTC-8, Jim foo.bar wrote: > > 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} "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 are subscribed to the Google > > Groups "Clojure" group. > > To post to this group, send email to clo...@googlegroups.com > > Note that posts from new members are moderated - please be patient > > with your first post. > > To unsubscribe from this group, send email to > > clojure+u...@googlegroups.com > > For more options, visit this group at > > http://groups.google.com/group/clojure?hl=en > > --- > > You received this message because you are subscribed to the Google > > Groups "Clojure" group. > > To unsubscribe from this group and stop receiving emails from it, send > > an email to clojure+u...@googlegroups.com . > > For more options, visit https://groups.google.com/groups/opt_out. > > -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.
Re: Programming clojure second Edition
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} "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 are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out. -- You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com Note that posts from new members are moderated - please be patient with your first post. To unsubscribe from this group, send email to clojure+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/clojure?hl=en --- You received this message because you are subscribed to the Google Groups "Clojure" group. To unsubscribe from this group and stop receiving emails from it, send an email to clojure+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/groups/opt_out.