<< Back to previous view

[CLJ-951] Clojure 1.3+ can't intern a dynamic var Created: 09/Mar/12  Updated: 30/Nov/12  Resolved: 30/Nov/12

Status: Closed
Project: Clojure
Component/s: None
Affects Version/s: Release 1.3, Release 1.4
Fix Version/s: None

Type: Enhancement Priority: Minor
Reporter: Ryan Senior Assignee: Unassigned
Resolution: Declined Votes: 0
Labels: None


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"}

Comment by Timothy Baldridge [ 30/Nov/12 3:57 PM ]

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.

Generated at Fri Sep 22 08:38:09 CDT 2017 using JIRA 4.4#649-r158309.