On Wednesday, March 13, 2013 2:46:06 PM UTC-7, puzzler wrote:

> On Wed, Mar 13, 2013 at 2:06 PM, Marko Topolnik 
> <marko.t...@gmail.com<javascript:>
> > wrote:
>
>
>> As far as I understand it, *set!* modifies the *thread-local* binding, 
>> just like the *binding* macro, but doesn't delimit a definite scope of 
>> validity for the binding. You can *set!* any dynamic var with the same 
>> semantics.
>>
>
> You can't just set! any dynamic var, you can only set! vars that are both 
> dynamic *and* have been bound again with the binding construct.
>
> => (def ^:dynamic a 2)
> #'user/a
> => (set! a 3)
> IllegalStateException Can't change/establish root binding of: a with set  
> clojure.lang.Var.set (Var.java:233)
> => (binding [a 1] (set! a 3))
> 3
>
>
> This is why I'm puzzled about how things like (set! *unchecked-math* true) 
> are handled.  Clearly, in this special case you can use set! without first 
> calling binding.
>

Not really a special case, although I suppose you could argue it either 
way. These vars, too, must be bound before being set!. But the code that 
binds them is in the compiler: 
https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/Compile.java#L72
 binds 
*unchecked-math*  *warn-on-reflection* before it starts compiling files. 
The only way you could make your own vars be set!able is to use them inside 
a context in which they've already been bound; for example, you could 
define a (let-me-set-stuff &body) macro and evaluate the user's code in 
that context. That's basically the same as how the compiler and the repl 
work: they run all of your code in a context where bindings are 
established. 

-- 
-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to