New *ns* implementation

20 views
Skip to first unread message

Antony Lee

unread,
May 14, 2012, 4:03:07 PM5/14/12
to clojure...@googlegroups.com
In my latest commit *ns* is now a regular Var (in clojure.core) set by compiler.executeCode before each eval().  This works well in general, I think (e.g. it easily solves #101); however I am not sure executeCode is the best place to set *ns* because (if I understand well) we are not always going to go through executeCode (for example in the case of interop... e.g. tests).
Please have a look and tell me what you think!
Antony

Konrad Hinsen

unread,
May 16, 2012, 3:38:02 AM5/16/12
to clojure...@googlegroups.com
Antony Lee writes:

> In my latest commit *ns* is now a regular Var (in clojure.core) set by
> compiler.executeCode before each eval().

Thanks, this lets me continue to work on macroexpand!

> This works well in general, I think (e.g. it easily solves #101);
> however I am not sure executeCode is the best place to set *ns*
> because (if I understand well) we are not always going to go
> through executeCode (for example in the case of
> interop... e.g. tests). Please have a look and tell me what you
> think! Antony

After fixing macroexpand to use *ns*, it works fine... *except* in a
test, as you supposed.

Basically, *ns* matters only for code that does namespace lookup.
That's the compiler, behind the scenes, plus eval and macroexpand.

Interop is a special situation because we'd have to decide on what *ns*
is supposed to be in code called from Python. It may be more pragmatic
to fix the testing framework (where this matters most right now) and
see if other problematic situations arise.

Konrad.

Antony Lee

unread,
May 18, 2012, 10:06:15 PM5/18/12
to clojure...@googlegroups.com
I modified the testing framework so that tests are run with *ns* properly set (to the namespace in which tests were defined), so your macro-tests.clj now work (the version with deftest that is commented out in your macroexpand branch).  More generally, this "only" requires running the code within a "with threadBindings({#'clojure.core/*ns*: blablabla}): <code>" (where #'clojure.core/*ns* is of course findItem(blablabla)).  (However, you'll need to change the imports to (:use [tests.utils :only [deftest]])).
I also updated the new-ns branch to setNS() at execution time instead of at compilation time (which is simpler but definitely bad).

Antony

2012/5/16 Konrad Hinsen <google...@khinsen.fastmail.net>

Konrad Hinsen

unread,
May 21, 2012, 1:58:08 AM5/21/12
to clojure...@googlegroups.com
Antony Lee writes:

> I modified the testing framework so that tests are run with *ns* properly set (to
> the namespace in which tests were defined), so your macro-tests.clj now work (the

Great, thanks! I'll write some more macro tests, and then submit a pull
request for the macroexpand stuff.

> I also updated the new-ns branch to setNS() at execution time instead of at
> compilation time (which is simpler but definitely bad).

My first reaction is that it should break some code. For example
macros that use eval. But I didn't check, this is just theory...

Konrad.

Konrad Hinsen

unread,
May 21, 2012, 7:54:28 AM5/21/12
to clojure...@googlegroups.com
--On 18 mai 2012 19:06:15 -0700 Antony Lee <anton...@berkeley.edu> wrote:

> I modified the testing framework so that tests are run with *ns* properly
> set (to the namespace in which tests were defined), so your
> macro-tests.clj now work (the version with deftest that is commented out
> in your macroexpand branch).  More generally, this "only" requires

I can't find this anywhere on github. Is there a repo I didn't look at?

Konrad.

Antony Lee

unread,
May 21, 2012, 12:06:17 PM5/21/12
to clojure...@googlegroups.com
It's in the new-ns branch (the relevant line is in bootstrap-clj-tests.py).  (There's also a cleanup branch on top of that.)
As for the timing of the call to setNS, this was just to make something like (do (py/print *ns*) (in-ns 'xyz) (py/print clojure.core/*ns*)) print <namespace 'user> <namespace 'xyz> instead of <namespace 'xyz> <namespace 'xyz> (which feels wrong :-))
Antony

2012/5/21 Konrad Hinsen <google...@khinsen.fastmail.net>
Reply all
Reply to author
Forward
0 new messages