On Oct 7, 2008, at 1:21 AM, Matthew D. Swank wrote: > > Typing #(nil) at a repl gives me: > > java.lang.NullPointerException (NO_SOURCE_FILE:1) > [Thrown class clojure.lang.Compiler$CompilerException] > [...] > However, (fn [] nil) is fine. > > Shouldn't they be equivalent? > > Thanks, > Matt
Here's a similar question and answer from the list archive that includes a cool tip for seeing the effect of reader macros: > On Fri, Mar 14, 2008 at 11:58 AM, Stephen C. Gilardi > <[EMAIL PROTECTED]> wrote: >> In SVN 748, the anonymous version of the identity function doesn't >> work as I >> expected: > [...] >> user=> (filter #(%) '(1 2 3)) >> java.lang.ClassCastException: clojure.lang.FixNum > > #(stuff) translates to (fn [args] (stuff)), so #(%) is (fn [x] (x)) - > you're trying to call the parameter as a no-arg function, which your > fixnums do not appreciate. > > #(do %) does what you want, but you may as well use identity directly > in this case. > > You can look at the expansion of reader macros (those that produce an > expansion) by quoting the form: > > user=> '#(%) > (fn* [p1__1016] (p1__1016)) > > Cheers, > Darshan Cheers, --Steve --~--~---------~--~----~------------~-------~--~----~ 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/clojure?hl=en -~----------~----~----~----~------~----~------~--~---