Hi Kurt,

Am 23.01.2009 um 05:23 schrieb zoglma...@gmail.com:

> (defn create-a [firstName lastName]
>  (defn getFirstName [] firstName)
>  (defn getLastName [] lastName)
>  (fn [operator & operands]
>    (apply operator operands)))

It's important to note that, regardless of the lexical context, def(n)  
creates global/top-level definitions (contrary to scheme, i believe).

> (def t (create-a "Kurt" "Z"))

Upon calling create-a, getFirstName and getLastName become globally  
defined functions. getFirstName will always return "Kurt", getLastName  
will always return "Z".

> ;How or why does this next line work? What is "getFirstName" in this
> context?
> (t getFirstName)

The value of t is the function (fn [operator & operands] (apply  
operator operands))), which is called with getFirstName as the  
operator arg. Since there are no further operands, applying operator  
to nothing just calls it and returns "Kurt".

Hope this helps.

Kind Regards,
achim

--~--~---------~--~----~------------~-------~--~----~
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
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to