On Fri, Jun 12, 2009 at 4:10 PM, Wrexsoul<d2387...@bsnow.net> wrote: > > Eh. That works. I tried (import java.io.File) and (import java.io/ > File), as well as (import (java.io File)), mimicking the syntax > of :import in ns. > > That's another of the problems -- some things, like import, are very > tersely documented at present, so the form the argument is to take is > not clear. My own preference when writing macros of making them quote > arguments for you that should probably be quoted might be part of it > -- see with-global-if-exists, which has (quote ~arg) in it for > precisely the reason that you will not want that argument evaluated.
ns is a macro, and as you suggest quotes things for you that you'll probably want quoted. However, 'require', 'import', 'use', etc. are functions (in 1.0) and so cannot quote your argument for you. > I only resorted to .hasRoot because defonce had odd side effects. In > particular, > > user=> foo > #<CompilerException java.lang.Exception: Unable to resolve symbol: foo > in this context (NO_SOURCE_FILE:0)> > user=> (ns-resolve *ns* 'foo) > nil > user=> (let [x (ns-resolve *ns* 'foo)] > (if x > (defonce foo nil))) > #'user/foo > user=> foo > nil > > So it looks like when the compiler expands defonce, it actually > evaluates a def right then and there, rather than the def only being > evaluated when the expansion of the defonce macro is evaluated. Yes, the var is interned in the namespace at compile time. This is true of all macros that expand to 'def', not just 'defonce'. That's one of the reasons that using 'def' other than at the top level is suspect. --Chouser --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---