On Nov 8, 6:46 pm, Alan Malloy <a...@malloys.org> wrote:
> On Nov 8, 4:44 pm, Stuart Halloway <stuart.hallo...@gmail.com> wrote:
> > > This is under clojure 1.2.0, 1.2.1, 1.3.0, though the error messages 
> > > differ.
>
> > > Consider a trivial project that `uses` midje:
>
> > >    (ns midje-aot.core
> > >      (:use midje.sweet))
>
> > > If it's aot-compiled, everything appears to go well:
>
> > >    1762 $ lein compile
> > >    Copying 6 files to /Users/marick/src/midje-aot/lib
> > >    Copying 1 file to /Users/marick/src/midje-aot/lib/dev
> > >    Compiling midje-aot.core
> > >    Compilation succeeded.
>
> > > But certain of the namespaces can't be loaded:
>
> > > 1766 $ lein repl
> > > REPL started; server listening on localhost port 40437
> > > user=> (require 'midje.semi-sweet)
> > > NullPointerException   clojure.lang.Compiler.lookupVar 
> > > (Compiler.java:6780)
>
> > > What could that exception mean? What's a starting point for debugging?
>
> > The full stack trace:
>
> >         clojure.lang.Compiler.lookupVar (Compiler.java:6780)
> >         clojure.lang.Compiler.isMacro (Compiler.java:6260)
> >         clojure.lang.Compiler.macroexpand1 (Compiler.java:6315)
> >         clojure.lang.Compiler.macroexpand (Compiler.java:6381)
> >         clojure.lang.Compiler.eval (Compiler.java:6449)
> >         clojure.lang.Compiler.eval (Compiler.java:6454)
> >         clojure.lang.Compiler.eval (Compiler.java:6431)
> >         clojure.core/eval (core.clj:2795)
> >         midje.util.report__init.load (:4)
> >         midje.util.report__init.<clinit> (:-1)
> >         java.lang.Class.forName0 (Class.java:-2)
> >         java.lang.Class.forName (Class.java:247)
>
> > Line 4 of midje.util.report is unusual in several ways:  it precedes the ns 
> > call, adds a second ns call, does an eval, and uses def forms not at the 
> > top level:
>
> > (when (= (class clojure.test/report) clojure.lang.MultiFn)
> >   (eval
> >    '(do (require 'clojure.test)
> >         (ns clojure.test)
> >         (defonce old-report clojure.test/report))))
>
> > Not sure where the problem is yet, and I have no time to look further 
> > tonight, but perhaps this will help somebody track the root cause.
>
> At least you could simplify this and avoid using eval, by using
> clojure.core/intern directly instead of trying to get the compiler to
> believe you're in that namespace. Grabbing the source for the defonce
> macro, here's a draft of how I might rewrite this to avoid eval:
>
> (let [ns-obj (the-ns (doto 'clojure.test require))
>       the-var (intern ns-obj 'old-report)]
>   (when-not (.hasRoot the-var)
>     (intern ns-obj 'old-report clojure.test/report)))
>
> Seems to have the same effect as the defonce in some simple testing.

Of course it's silly to use intern the second time: (.setRoot the-var
clojure.test/report) would have been simpler. And of course I don't
know whether this will fix the problem, but it seems like it should at
least simplify it.

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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