Hi Josip,

Have a look in jvm/clojure/lang/Repl.java which demonstrates creating
and entering the 'user namespace.

The key is that you need to wrap the call to in-ns in
Var.pushThreadBindings(IPersistentMap) / Var.popThreadBindings().

This is analogous to:

(binding [*ns* *ns*] ;; bind a thread-local copy of *ns* so changes
are isolated to this thread
  (....))

See also:
 http://clojure.org/vars

The root binding of Clojure vars are immutable, but using the
(binding) construct you can override the value within the scope of the
(binding) form.

The clojure/*ns* var is no different and this is why you see Repl.java
establishes a thread-local binding before evaluating user code. This
allows you to change the namespace at the REPL.

Hope this helps.

/mike.



On Wed, Sep 3, 2008 at 5:06 PM, Josip Gracin <[EMAIL PROTECTED]> wrote:
>
> Hi!
>
> Why is the following code throwing an exception?
>
>    PushbackReader rdr = new PushbackReader( new StringReader( "(in-ns
> 'user)" ) );
>    Object input = LispReader.read(rdr, false, null, false );
>    clojure.lang.Compiler.eval( input );
>
> java.lang.IllegalStateException: Can't change/establish root binding
> of: *ns* with set
>        at clojure.lang.Var.set(Var.java:170)
>        at clojure.lang.RT$1.invoke(RT.java:206)
>        at clojure.eval__2237.invoke(Unknown Source)
>        at clojure.lang.Compiler.eval(Compiler.java:3847)
>        ...
>
> I'm trying to set the namespace so that subsequent expressions are
> evaluated within it.
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to