I wonder, why (resolve 'n/x) ;; => nil
silently if n
is not required? I see at least 2 other choices:
1) auto require n
(possibly bad due side-effects while classloading)
2) throw error
I think there's a new variant of resolve that auto-requires
an error could arguably be more useful since resolve
could fail for two different reasons and you can't tell which it is based on nil
, but that would be a breaking change, and I'm 103% certain that won't happen for something in clojure.core
without providing a lot more benefit than this
yep, I don’t believe in change, just wonder about the design decision..
and this is actually not only about calling resolve
directly. Same applies if it’s a fn call (n/x args)
- why not to try to autoload ns
what's similar about this?
user=> (n/x 42)
Syntax error compiling at (REPL:1:1).
No such namespace: n
*fixed, I meant fully qualified call could try auto-require
see requiring-resolve
in 1.10
my initial reaction is that that's a crazy idea, but I'm having trouble putting my finger on really compelling reasons; I bet other people will have ideas
namespace loading is side effecty, you don't want it to happen automagically
but why would you type foo/bar
if you didn't want it loaded?
I was thinking along those lines, but couldn't put my finger on why that was a good enough reason
I think there are questions of when the loading happens
and it ends up in similar territory to forward declarations
like for (defn f [] (foo/bar))
, when would foo be loaded? at runtime or compile time? when the class that implements f is loaded or when f is actually invoked?
which isn't to say you can't decided on answers to the question, it is just that the design space is larger then you would expect and someone would have to traverse it
somehow I hadn't even thought of the "when the function is loaded vs first called" question
I guess it'd have to be loaded, if you want a compile error for missing bar
so that much at least seems well-defined
it has to be compiled time if foo/bar is a macro
oh right, which you can't even tell w/o loading it