Op vrijdag 24 oktober 2014 15:32:33 UTC+2 schreef Laurens Van Houtven: > > Hi Roelof, > > On 24 Oct 2014, at 15:12, Roelof Wobben <[email protected] <javascript:>> > wrote: > > > I understand that part but when I look at the map part there is no x. > When I look at the function no x. > > I’m assuming you mean that when you look at the function, you do see the x > — it’s right there, both in the argument list and in the body. > > > So how does Clojure know what the value of x is. > > Then you haven’t quite understood it ;-) > > Consider: > > (defn double [x] (* x 2)) > > i.e. a function that doubles its argument. When you call (double 4), how > does Clojure “know” what x is? The same way that you call double with 4, > map applies the function you pass it to each element of the collection you > pass it. So, for example: (map double [3 5 7]) will basically do [(double > 3) (double 5) (double 7)]. The “x” is “replaced”, if you will, just like it > is with regular function application. That’s all map is: a bunch of > function applications and tying the results together :-) > > *(except that it actually returns a lazy seq, not a vector, but that’s > besides the point here). > > hth > lvh >
I understand that part. so we have (map second-item collection) where second-item and collection are arguments of map. Then we have second-item ( fn [x] (get x 2) which can be read as : ( second-item [x] (get x 2) . in the map there is only ( map second-item collection) or is the collection a argument of second-item and a argument of map. Roelof -- 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 --- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.
