Re: Use of eval
Gary, You are probably removing try/catch as well. ClassNonFoundException is expected and silenced with catch. (defn cl-factory Returns a Commons Logging-based implementation of the LoggerFactory protocol, or nil if not available. [] (try (Class/forName foo.bar) ; eval removed (catch Exception e nil))) On Nov 18, 5:16 pm, Gary Trakhman gary.trakh...@gmail.com wrote: I get this when i try it in a blank project, removing the eval and the quote: Unknown location: error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log core.clj:16:8: error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log (core.clj:16) Compilation failed. -- 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
Re: Use of eval
I think you're confusing compile-time with run-time. A try-catch wouldn't affect the compiler. Perhaps you actually have commons-logging in your classpath? It's pulled in by many libraries. Or you forgot to remove the quote in addition to removing the eval in your testing. Here's the code that fails to compile. All I did was remove eval and the quote around the 'do'. (ns testclj.core) (defn cl-factory Returns a Commons Logging-based implementation of the LoggerFactory protocol, or nil if not available. [] (try (Class/forName org.apache.commons.logging.Log) (do (extend org.apache.commons.logging.Log Logger {:enabled? (fn [logger# level#] (condp = level# :trace (.isTraceEnabled logger#) :debug (.isDebugEnabled logger#) :info (.isInfoEnabled logger#) :warn (.isWarnEnabled logger#) :error (.isErrorEnabled logger#) :fatal (.isFatalEnabled logger#) (throw (IllegalArgumentException. (str level#) :write! (fn [logger# level# e# msg#] (if e# (condp = level# :trace (.trace logger# msg# e#) :debug (.debug logger# msg# e#) :info (.info logger# msg# e#) :warn (.warn logger# msg# e#) :error (.error logger# msg# e#) :fatal (.fatal logger# msg# e#) (throw (IllegalArgumentException. (str level# (condp = level# :trace (.trace logger# msg#) :debug (.debug logger# msg#) :info (.info logger# msg#) :warn (.warn logger# msg#) :error (.error logger# msg#) :fatal (.fatal logger# msg#) (throw (IllegalArgumentException. (str level#))}) (reify LoggerFactory (name [_#] org.apache.commons.logging) (get-logger [_# logger-ns#] (org.apache.commons.logging.LogFactory/getLog (str logger- ns#) (catch Exception e nil))) On Tue, Nov 22, 2011 at 1:34 PM, vitalyper vitaly...@yahoo.com wrote: Gary, You are probably removing try/catch as well. ClassNonFoundException is expected and silenced with catch. (defn cl-factory Returns a Commons Logging-based implementation of the LoggerFactory protocol, or nil if not available. [] (try (Class/forName foo.bar) ; eval removed (catch Exception e nil))) On Nov 18, 5:16 pm, Gary Trakhman gary.trakh...@gmail.com wrote: I get this when i try it in a blank project, removing the eval and the quote: Unknown location: error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log core.clj:16:8: error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log (core.clj:16) Compilation failed. -- 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 -- 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
Re: Use of eval
Also I think this line doesn't actually do anything: (Class/forName foo.bar) It will effectively just ask the classloader to load the class. You removed more than the eval in your referenced code, you removed the code that did anything. That code needs to be there. It's eval'd because it's not guaranteed to be compilable for projects without commons-logging in their classpath. (defn cl-factory Returns a Commons Logging-based implementation of the LoggerFactory protocol, or nil if not available. [] (try (Class/forName foo.bar) ; eval removed (catch Exception e nil))) -- 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
Re: Use of eval
Gary, You were right with your initial reply. Sorry I did not get it. Thanks for your help in understanding this. On Nov 22, 1:58 pm, Gary Trakhman gary.trakh...@gmail.com wrote: Also I think this line doesn't actually do anything: (Class/forName foo.bar) It will effectively just ask the classloader to load the class. You removed more than the eval in your referenced code, you removed the code that did anything. That code needs to be there. It's eval'd because it's not guaranteed to be compilable for projects without commons-logging in their classpath. (defn cl-factory Returns a Commons Logging-based implementation of the LoggerFactory protocol, or nil if not available. [] (try (Class/forName foo.bar) ; eval removed (catch Exception e nil))) -- 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
Re: Use of eval
If you try to do it without eval and you don't have the apache stuff on your classpath, then you get an exception while compiling, before class/forname is ever called. On Nov 22, 11:33 am, vitalyper vitaly...@yahoo.com wrote: Gary, You were right with your initial reply. Sorry I did not get it. Thanks for your help in understanding this. On Nov 22, 1:58 pm, Gary Trakhman gary.trakh...@gmail.com wrote: Also I think this line doesn't actually do anything: (Class/forName foo.bar) It will effectively just ask the classloader to load the class. You removed more than the eval in your referenced code, you removed the code that did anything. That code needs to be there. It's eval'd because it's not guaranteed to be compilable for projects without commons-logging in their classpath. (defn cl-factory Returns a Commons Logging-based implementation of the LoggerFactory protocol, or nil if not available. [] (try (Class/forName foo.bar) ; eval removed (catch Exception e nil))) -- 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
Re: Use of eval
My speculation is that the eval is required in the case that commons-logger is not in the classpath. The code wouldn't compile without 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
Re: Use of eval
I don't think you are right - it does compiles without it. After more thinking my guess is that eval is used to combine extend and reify in the same function. Let's see if somebody else could shed a light on this. On Nov 18, 12:45 pm, Gary Trakhman gary.trakh...@gmail.com wrote: My speculation is that the eval is required in the case that commons-logger is not in the classpath. The code wouldn't compile without 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
Re: Use of eval
I get this when i try it in a blank project, removing the eval and the quote: Unknown location: error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log core.clj:16:8: error: java.lang.ClassNotFoundException: org.apache.commons.logging.Log (core.clj:16) Compilation failed. -- 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