"Vars" problem

92 views
Skip to first unread message

xlarsx

unread,
Dec 31, 2010, 2:12:39 PM12/31/10
to Clojure
Good day
Before anything I'd like to thank you for your time

I've the following problem:
user=> (def x 1)
#'user/x
user=> (def y 1)
#'user/y
user=> (+ x y)
2
user=> (binding [x 2 y 3] (+ x y))
IllegalStateException Can't dynamically bind non-dynamic var: user/x
clojure.lang.Var.pushThreadBindings (Var.java:339)

The origin of this code is: http://clojure.org/vars

Thank you

Luis Alejandro Rangel Sánchez

Meikel Brandmeyer

unread,
Dec 31, 2010, 2:32:10 PM12/31/10
to clo...@googlegroups.com
Hi,

This a change in the upcoming 1.3 release. Vars have to be declared explicitly dynamic to be able to rebind them via binding. But I don't know the exact syntax how to do this.

Sincerely
Meikel

Sean Corfield

unread,
Dec 31, 2010, 2:45:21 PM12/31/10
to clo...@googlegroups.com
On Fri, Dec 31, 2010 at 11:12 AM, xlarsx <xla...@gmail.com> wrote:
> user=> (binding [x 2 y 3] (+ x y))
> IllegalStateException Can't dynamically bind non-dynamic var: user/x
> clojure.lang.Var.pushThreadBindings (Var.java:339)
>
> The origin of this code is: http://clojure.org/vars

The docs refer to Clojure 1.2 but the error you're seeing indicates
you're running Clojure 1.3 (alpha/snapshot), yes?

In Clojure 1.3, variables must be declared dynamic in order to change
their bound value:

(def ^:dynamic x 1)
(def ^:dynamic y 1)


(binding [x 2 y 3] (+ x y))

--
Sean A Corfield -- (904) 302-SEAN
Railo Technologies, Inc. -- http://getrailo.com/
An Architect's View -- http://corfield.org/

"If you're not annoying somebody, you're not really alive."
-- Margaret Atwood

Reply all
Reply to author
Forward
0 new messages