When you're using fn as a parameter name, you are shadowing the fn
special form.  Like Mark Volkmann said, it is best that you refrain
from using special form names and core macros and functions names to
name your own things.  f is the prefered notation to name a function
passed to another function.

Be safe,

Vince.

On Jan 15, 2:12 pm, "Hugh Winkler" <hwink...@gmail.com> wrote:
> I just encountered a surprise attempting to return a function from a
> function. In the below case, if the function parameter is named "fn",
> then calling the function throws an exception. If the function
> parameter is named "f", no problem. (Using svn as of yesterday)
>
> (defn no-problem[f]
>   (fn [] (apply f [])))
> (no-problem #(prn 99))  ;; returns a function as expected
>
> (defn problem[fn]
>   (fn [] (apply fn [])))    ;; same code as above but renamed
> function parameter to "fn"
>
> (problem #(prn 99)) ;; prints out "99" and throws an exception :
>
> java.lang.IllegalArgumentException: Wrong number of args passed to:
> dispatch$eval--3402$fn (NO_SOURCE_FILE:0)
>  [Thrown class clojure.lang.Compiler$CompilerException]
>
> Restarts:
>  0: [ABORT] Return to SLIME's top level.
>  1: [CAUSE] Throw cause of this exception
>
> Backtrace:
>  0: clojure.lang.Compiler.eval(Compiler.java:4179)
>  1: clojure.core$eval__3733.invoke(core.clj:1582)
>  --more--
>
> Regards,
>
> Hugh
--~--~---------~--~----~------------~-------~--~----~
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