(defn double [x] (* x 2))

See, x is right there ^

Now, I do (double 10). How does Clojure “know what the x is”? There’s no x in 
that expression.

Exactly the same with map. The x is just a name; it doesn’t matter what it is. 
The only thing that matters is that you call that function (whether it’s double 
or second-item or whatever) with a single argument. In (double 10), I’m calling 
it with 10. In (map second-item coll), map is calling second-item with each of 
the items in coll. These are exactly the same thing: in both cases it’s just 
function application.

hth
lvh


On 24 Oct 2014, at 15:56, Roelof Wobben <[email protected]> wrote:

> Sorry but I still do not have a clue how clojure knows what x is.
> 
> the first part where x is mentioned is the fn part and on the map part there 
> is no mention about x.  
> 
> Roelof
> 
> 
> Op vrijdag 24 oktober 2014 15:51:30 UTC+2 schreef Laurens Van Houtven:
> Hi Roelof, 
> 
> > I understand that part. 
> > 
> > so we have (map second-item collection)  where second-item and collection 
> > are arguments of map. 
> 
> Yep. 
> 
> > Then we have second-item ( fn [x] (get x 2)   
> > which can be read as : 
> > 
> > ( second-item [x] (get x 2)  . 
> 
> This makes no sense to me. second-item is a fn. In this syntax, (malformed 
> because of a missing closing bracket), you are calling second-item with [x] 
> and (get x 2), without having defined x. 
> 
> > in the map there is only ( map second-item collection) 
> > 
> > or is the collection a argument of second-item and a argument of map. 
> 
> No. second-item and collections are the arguments of map. map will call 
> second-item for each element in coll. map’s job is to “pull apart” the 
> collection, element by element, pass it to f, and give you the result back. 
> 
> hth 
> lvh 
> 
> -- 
> 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.

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to