OK, thanks all, got it.

Hugh


On Thu, Jan 15, 2009 at 1:33 PM, redc...@gmail.com <redc...@gmail.com> wrote:
>
> by having a parameter named "fn" you are shadowing the global "fn"
> so what is happening is the "(fn ...)" form inside the function is
> trying to apply the function you passed in to the arguments. the
> function
> you passed in takes no arguments so you get the " Wrong number of args
> passed to"
> exception.
>
> On Jan 15, 11:12 am, "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