On Jun 29, 2009, at 10:11 AM, Nicolas Oury wrote:
I am not sure, but I believe it's due to *warn-on-reflection* beingbound by the compiler/REPL before evaluating (set! *warn-on- reflection*true). When I looked, the REPL was called within a macro 'with-bindings repl' that expands to (binding [.... *warn-on-reflection* .... ] repl) allowing the execution of REPL to set! *war-on-reflection* and some other similar vars. (*ns*, *compile-files*, *compile-path*, etc...) I suppose the compiler does a similar thing, but I have never looked.
That's correct. You can see the vars that are set!-ale in the REPL in: user=> (doc clojure.main/with-bindings) ------------------------- clojure.main/with-bindings ([& body]) MacroExecutes body in the context of thread-local bindings for several vars
that often need to be set!: *ns* *warn-on-reflection* *print-meta* *print-length* *print-level* *compile-path* *command-line-args* *1 *2 *3 *e nilIn your own REPL, you could make *math-context* set!-able by launching a new repl wrapped in code that binds *math-context*:
user=> (binding [*math-context* *math-context*] (clojure.main/repl)) user=> (set! *math-context* (java.math.MathContext. 4)) #<MathContext precision=4 roundingMode=HALF_UP> user=> (+ 3 1.55555555M) 4.556M user=> (set! *math-context* (java.math.MathContext. 6)) #<MathContext precision=6 roundingMode=HALF_UP> user=> (+ 3 1.55555555M) 4.55556M user=>It seems to me that clojure.main/with-bindings should be enhanced provide a root binding for *math-context* so it's set!-able at the repl.
Does anyone have any objection to or support for that idea? --Steve
smime.p7s
Description: S/MIME cryptographic signature