The name given an anonymous function can only be used within the scope of
that function.

This will work:

(fn my-func1 [x] (my-func x)) ; Leads to infinite recursion, of course

This won't work because my-func1 is called outside of the function's
lexical scope:

(fn my-func1 [x] x)
(my-func1 100)

However, functions defined with defn use a global var, so they're not
limited to any particular lexical scope.

On Fri, Aug 31, 2012 at 11:52 AM, Erlis Vidal <[email protected]> wrote:

> Hi guys,
>
> I've been reading but I'm still confused about the difference between an
> anonymous function with name vs a defn function
>
> (fn my-func1[x] x)
>
> (defn my-func2[x] x)
>
> Thanks,
> Erlis
>
> --
> 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 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

Reply via email to