Re: Confusion about binding *ns* before defining a var

2014-05-30 Thread ian.tegebo
Thanks Steve! It's clear to me now that I neither understand Clojure's compilation model, nor its special forms. I also see that I probably don't want def to respect dynamic scope, but instead would want a compile-time (non top-level) version of in-ns (or an explanation about why that's a bad

Re: Confusion about binding *ns* before defining a var

2014-05-30 Thread Stephen Gilardi
On May 30, 2014, at 12:57 AM, ian.tegebo wrote: > I don't see the reason why def should behave as it currently does; it seems > like it should lookup the current thread-binding for *ns*, making the second > case's use of eval unnecessary. Since it doesn't, I'd like to know why it > couldn't

Re: Confusion about binding *ns* before defining a var

2014-05-30 Thread Luc Prefontaine
*ns* is bound at execution time, not at compile time. Eval here postpones the definition at runtime after the bindings have been evaluated and *ns* gets rebinded. Otherwise the definition would be created at compile time in the namespace of the caller. The full form has to be compiled to get th

Re: Confusion about binding *ns* before defining a var

2014-05-29 Thread ian.tegebo
On Thursday, May 29, 2014 8:43:58 PM UTC-7, squeegee wrote: > > > On May 29, 2014, at 7:11 PM, ian.tegebo > > wrote: > > user> (binding [*ns* (the-ns 'blah)] (defn foo [])) > #'user/foo > user> (binding [*ns* (the-ns 'blah)] (eval '(defn foo []))) > #'blah/foo > > In the first case, the defn form

Re: Confusion about binding *ns* before defining a var

2014-05-29 Thread Stephen Gilardi
On May 29, 2014, at 7:11 PM, ian.tegebo wrote: > user> (binding [*ns* (the-ns 'blah)] (defn foo [])) > #'user/foo > user> (binding [*ns* (the-ns 'blah)] (eval '(defn foo []))) > #'blah/foo clojure.core/eval evaluates a form by compiling it and then executing the compiled code. For a def form,

Confusion about binding *ns* before defining a var

2014-05-29 Thread ian.tegebo
I went to write a context macro so that I could define functions in another namespace. After the obligatory googling, I found "with-ns": http://richhickey.github.io/clojure-contrib/with-ns-api.html Clicking through to look at the source, I was surprised to see that "eval" was being wrapped aro