Re: def partially done when used in if

2017-06-30 Thread Sean Corfield
You can see it at work in this: user=> foo (unable to resolve foo) user=> (when nil (def foo 42)) nil user=> foo (unbound var foo) When a ‘def’ form is _compiled_ -- which happens in the above case because the whole form must be compiled – then it interns the var. The ‘d

Re: def partially done when used in if

2017-06-30 Thread Didier
I admit, this is very surprising. It looks like evaluation happens in two pass, like first it finds all defs and declares them, interning the symbol and creating an unbound var. And on a second pass it evaluates the full form. Can someone more informed confirm or explain in more details what's r

Re: def partially done when used in if

2017-06-29 Thread Justin Smith
It creates an "undefined" var if the def gets compiled but doesn't get run. This isn't the same as an "undefined behavior" as is documented for languages that have formal specifications (clojure of course has none). I did qualify that def / defn inside other forms are "generally" a sign of bad desi

Re: def partially done when used in if

2017-06-29 Thread Kaiming Yang
Thanks Justin, Sadly in my case those mutable container will not work because I was making a monkey-patch to a bug in a macro from other package. Despite what I was doing, I think "a bad design" in clojure spec is too weak to fit this situation. If someone tells me "it is a bad design" I would

Re: def partially done when used in if

2017-06-29 Thread Justin Smith
Clojure's compiler (there's no interpreter) creates vars for every def inside a form it compiles. Before the def actually runs it's unbound (as if you had used declare). Generally def and defn that are not top level forms are signs of a bad design. If you need runtime rebinding use a proper mutabl

def partially done when used in if

2017-06-29 Thread Kaiming Yang
Hi, Recently encountered a weird issue, A def in if clause declared a var but left it unbound. I encountered this issue when I was trying to implement something like "define a symbol if it is not defined yet". Naively I tried: (if (nil? (resolve 'foo)) (def foo 42)) ; Cannot use (def foo (