It might help you understand what's going on to bind the fn to a name and 
poke at it a bit:
(let [by-five (fn [x] (* 5 x))]
  [(by-five 5)
   (by-five 6)
   (by-five 7)])
;; => [25 30 35]

This results in a vector <http://clojure.org/data_structures#Data 
Structures-Vectors (IPersistentVector)> with the result of multiplying 5 by 
5, 6, and 7 respectively. The let special form 
<http://clojure.org/special_forms#Special Forms--(let [bindings* ] exprs*)> 
allows 
you to bind values to names within the body of the let.
You can see that "by-five" is in front of 5, 6, 7. That's because in 
Clojure (and Lisps in general) the first element of a list (parentheses) is 
viewed as a function to be invoked (in this case "by-five") and the rest of 
the list are the parameters to the function.

This evaluates to the same as the let form:
[((fn [x] (* 5 x)) 5)
 ((fn [x] (* 5 x)) 6)
 ((fn [x] (* 5 x)) 7)]
;; => [25 30 35]

On Friday, January 2, 2015 8:13:41 PM UTC-5, novato wrote:
>
> I choose clojure as my first programming language after some research. I 
> am learning by doing Clojure Koans <http://clojurekoans.com/> exercises. 
> I reached to the functions "lesson" and I have a doubt on the following 
> code:
> ((fn [x] (* 5 x)) 5)
>
> Why is that the last 5 is outside the fn parentheses? Why this doesn't 
> work? 
> (fn [x] (* 5 x) 5)
>
> Thanks in advice for the clarification and excuse my poor english.
>

-- 
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/d/optout.

Reply via email to