Hi Roelof, On 24 Oct 2014, at 15:12, Roelof Wobben <rwob...@hotmail.com> 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
signature.asc
Description: Message signed with OpenPGP using GPGMail