Details
-
Type:
Enhancement
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Declined
-
Affects Version/s: Release 1.3, Release 1.4
-
Fix Version/s: None
-
Component/s: None
-
Labels:None
-
Approval:Not Approved
Description
In Clojure 1.3+, interned vars don't set the dynamic field in clojure.lang.Var and can't be used in a binding:
user=> (intern ns (with-meta 'dyna-var {:dynamic true}) 100)
user=> (binding [dyna-var "one hundred"] dyna-var)
;=> IllegalStateException Can't dynamically bind non-dynamic var: user/dyna-var clojure.lang.Var.pushThreadBindings (Var.java:339)
The var has the right metadata
user=> (meta #'dyna-var)
;=> {:ns #<Namespace user>, :name dyna-var, :dynamic true}
But doesn't set the dynamic flag on the var:
user=> (.isDynamic #'dyna-var)
;=> false
The push-thread-bindings function looks for the .dynamic flag. Vars created via def have it:
user=> (def ^:dynamic def-dyna-var 100)
user=> (.isDynamic #'def-dyna-var)
;=> true
Along with the metadata
user=> (meta #'def-dyna-var)
{:ns #<Namespace user>, :name def-dyna-var, :dynamic true, :line 6, :file "NO_SOURCE_PATH"}
Activity
| Field | Original Value | New Value |
|---|---|---|
| Approval | Not Approved [ 10008 ] | |
| Issue Type | Defect [ 1 ] | Enhancement [ 4 ] |
| Resolution | Declined [ 2 ] | |
| Status | Open [ 1 ] | Closed [ 6 ] |
This is actually an enhancement. The Var.java and Namespace.java code does not attempt to read the metadata on the var. Instead, the compiler handles this at compile time. If you would like to see this behavior changed, feel free to bring it up on clojure-dev, and we'll discuss it.
Closing until that time.