On Dec 1, 2:53 pm, Rich Hickey <[EMAIL PROTECTED]> wrote:
> Could you give some more information on the error you get (when log4j
> is not found), especially a stack trace? And also some more
> information on how your gjdv.logging macros work?

Minimal example to produce the results:

3 libraries: extdep, nodep and bad

extdep and nodep both define a function/macro "workhorse". bad
uses one of these workhorse functions to define its own
"nice-wrapper".  "nice-wrapper" can be a function or macro,
it just gives a different exception.

(ns extdep)
(defn workhorse []
  org.apache.log4j.Logger)

(ns nodep)
(defn workhorse []
  java.util.logging.Logger)

(ns bad)
(defn extdep-available? []
  (try (Class/forName "org.apache.log4j.Logger")
    (catch ClassNotFoundException x
      false)))
(if (extdep-available?)
  (use 'extdep)
  (use 'nodep))
(defmacro nice-wrapper []
  `(workhorse))

user=> (set! *compile-path* ".")
.
user=> (compile 'extdep)
extdep
user=> (compile 'nodep)
nodep
user=> (compile 'bad)
bad
user=> (bad/nice-wrapper)
org.apache.log4j.Logger
Maverick:/tmp/asdf gj$ rm /Users/gj/.clojure/log4j-1.2.15.jar
Maverick:/tmp/asdf gj$ clojure
Listening...
Clojure
user=> (require 'bad)
nil
user=> (bad/nice-wrapper)
java.lang.Exception: No such namespace: extdep (NO_SOURCE_FILE:2)
user=> (.printStackTrace *e)
java.lang.Exception: No such namespace: extdep (NO_SOURCE_FILE:2)
        at clojure.lang.Compiler.analyze(Compiler.java:3922)
        at clojure.lang.Compiler.analyze(Compiler.java:3880)
        at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2724)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:4075)
        at clojure.lang.Compiler.analyze(Compiler.java:3907)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:4061)
        at clojure.lang.Compiler.analyze(Compiler.java:3907)
        at clojure.lang.Compiler.analyze(Compiler.java:3880)
        at clojure.lang.Compiler$BodyExpr$Parser.parse(Compiler.java:
3585)
        at clojure.lang.Compiler$FnMethod.parse(Compiler.java:3428)
        at clojure.lang.Compiler$FnMethod.access$1100(Compiler.java:
3307)
        at clojure.lang.Compiler$FnExpr.parse(Compiler.java:2913)
        at clojure.lang.Compiler.analyzeSeq(Compiler.java:4071)
        at clojure.lang.Compiler.analyze(Compiler.java:3907)
        at clojure.lang.Compiler.eval(Compiler.java:4107)
        at clojure.core$eval__3452.invoke(core.clj:1463)
        at clojure.main$repl__5005$fn__5020.invoke(main.clj:100)
        at clojure.main$repl__5005.doInvoke(main.clj:96)
        at clojure.lang.RestFn.invoke(RestFn.java:426)
        at clojure.main$repl_opt__5045.invoke(main.clj:153)
        at clojure.main$_main__5069.doInvoke(main.clj:228)
        at clojure.lang.RestFn.invoke(RestFn.java:402)
        at clojure.lang.AFn.applyToHelper(AFn.java:191)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.main.main(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.Exception: No such namespace: extdep
        at clojure.lang.Compiler.resolveIn(Compiler.java:4229)
        at clojure.lang.Compiler.resolve(Compiler.java:4203)
        at clojure.lang.Compiler.analyzeSymbol(Compiler.java:4180)
        at clojure.lang.Compiler.analyze(Compiler.java:3895)
        ... 29 more
nil
user=>

For completeness, here is the stacktrace if "nice-wrapper" is a
function:
user=> (.printStackTrace *e)
java.lang.IllegalStateException: Var extdep/workhorse is unbound.
(NO_SOURCE_FILE:0)
        at clojure.lang.Compiler.eval(Compiler.java:4120)
        at clojure.core$eval__3452.invoke(core.clj:1463)
        at clojure.main$repl__5005$fn__5020.invoke(main.clj:100)
        at clojure.main$repl__5005.doInvoke(main.clj:96)
        at clojure.lang.RestFn.invoke(RestFn.java:426)
        at clojure.main$repl_opt__5045.invoke(main.clj:153)
        at clojure.main$_main__5069.doInvoke(main.clj:228)
        at clojure.lang.RestFn.invoke(RestFn.java:402)
        at clojure.lang.AFn.applyToHelper(AFn.java:191)
        at clojure.lang.RestFn.applyTo(RestFn.java:137)
        at clojure.main.main(Unknown Source)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke
(NativeMethodAccessorImpl.java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke
(DelegatingMethodAccessorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:585)
        at jline.ConsoleRunner.main(ConsoleRunner.java:69)
Caused by: java.lang.IllegalStateException: Var extdep/workhorse is
unbound.
        at clojure.lang.Var.get(Var.java:137)
        at bad$nice_function__244.invoke(bad.clj:10)
        at user$eval__235.invoke(Unknown Source)
        at clojure.lang.Compiler.eval(Compiler.java:4109)
        ... 15 more
nil

And also, new since yesterday, I found that the following works:

(ns bad)
(defn extdep-available? []
  (try (Class/forName "org.apache.log4j.Logger")
    (catch ClassNotFoundException x
      false)))
(defn wns [symstr]
  (symbol (if (extdep-available?)
            "extdep"
            "nodep")
          symstr))
(if (extdep-available?)
  (require 'extdep)
  (require 'nodep))
(defmacro nice-wrapper []
  `(~(wns "workhorse")))


--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to