Should you pass in nil, the 'when' will guard against a NPE. On Mon, Mar 8, 2010 at 2:32 PM, Martin Hauner <[email protected]> wrote:
> Hi, > > there is an example in programming clojure (Chapter 2.6, Where is my > for loop? on page 52) > that I don't really get. > > (defn index-filter [pred coll] > (when pred > (for [[idx elt] (indexed coll) :when (pred elt)] idx))) > > The explanation in the book explains the for/:when but not the > when. ;) What I do not understand is > why there is the outer (when) . > > If I remove the (when): > > (defn index-filter-2 [pred coll] > (for [[idx elt] (indexed coll) :when (pred elt)] idx)) > > it seems to do the same as the first version. So what's the reason for > the (when) ? > > -- > 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]<clojure%[email protected]> > 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 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
