Can't dynamically bind non-dynamic var

2012-11-16 Thread faenvie
hi clojure-users,

for testing an app that uses quil, i want to mock out some 
function-calls to the quil-library ... when i do it like this:

(ns myapp
  (:use clojure.test)
  (:require [quil.core :as q]))

(deftest
  (binding [q/height (fn [] 400)]
  (is  400 (q/height

i get an Exception that says:

actual: java.lang.IllegalStateException: Can't dynamically bind non-dynamic 
var: quil.core/height

Any hints, how this an be solved or circumvented ?

thanks  have a successful day 

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

Re: Can't dynamically bind non-dynamic var

2012-11-16 Thread Baishampayan Ghose
Check out 'with-redefs' in clojure.core.

-BG

Sent from phone. Please excuse brevity.
On 16 Nov 2012 08:02, faenvie fanny.aen...@gmx.de wrote:

 hi clojure-users,

 for testing an app that uses quil, i want to mock out some
 function-calls to the quil-library ... when i do it like this:

 (ns myapp
   (:use clojure.test)
   (:require [quil.core :as q]))

 (deftest
   (binding [q/height (fn [] 400)]
   (is  400 (q/height

 i get an Exception that says:

 actual: java.lang.IllegalStateException: Can't dynamically bind
 non-dynamic var: quil.core/height

 Any hints, how this an be solved or circumvented ?

 thanks  have a successful day

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

Re: Can't dynamically bind non-dynamic var

2012-11-16 Thread Jay Fields
agreed. also, I prefer
(constantly 400)
over
(fn [] 400)

On Fri, Nov 16, 2012 at 8:11 AM, Baishampayan Ghose b.gh...@gmail.com wrote:
 Check out 'with-redefs' in clojure.core.

 -BG

 Sent from phone. Please excuse brevity.

 On 16 Nov 2012 08:02, faenvie fanny.aen...@gmx.de wrote:

 hi clojure-users,

 for testing an app that uses quil, i want to mock out some
 function-calls to the quil-library ... when i do it like this:

 (ns myapp
   (:use clojure.test)
   (:require [quil.core :as q]))

 (deftest
   (binding [q/height (fn [] 400)]
   (is  400 (q/height

 i get an Exception that says:

 actual: java.lang.IllegalStateException: Can't dynamically bind
 non-dynamic var: quil.core/height

 Any hints, how this an be solved or circumvented ?

 thanks  have a successful day

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


Can't dynamically bind non-dynamic var

2011-11-12 Thread Kevin Albrecht
I was experimenting with dynamic binding of vars with Clojure 1.3, as 
described on  http://clojure.org/vars and got this error:

user= (def x 1)
user= (binding [x 2] x)
IllegalStateException Can't dynamically bind non-dynamic var: 
clojure.core/x clojure.lang.Var.pushThreadBindings

I figured out the solution to this on a blog entry: 
http://blog.japila.pl/2011/03/cant-dynamically-bind-non-dynamic-var-in-clojure-1-3/
 (use 
^:dynamic when defining x)

Is this new feature documented anywhere in the official documentation?

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

Re: Can't dynamically bind non-dynamic var

2011-11-12 Thread Ben Smith-Mannschott
On Sat, Nov 12, 2011 at 18:37, Kevin Albrecht onlya...@gmail.com wrote:
 I was experimenting with dynamic binding of vars with Clojure 1.3, as
 described on  http://clojure.org/vars and got this error:
 user= (def x 1)
 user= (binding [x 2] x)
 IllegalStateException Can't dynamically bind non-dynamic var: clojure.core/x
 clojure.lang.Var.pushThreadBindings
 I figured out the solution to this on a blog
 entry: http://blog.japila.pl/2011/03/cant-dynamically-bind-non-dynamic-var-in-clojure-1-3/ (use
 ^:dynamic when defining x)
 Is this new feature documented anywhere in the official documentation?

You'll find it here:

https://github.com/clojure/clojure/blob/master/changes.md

under the heading Earmuffed Vars Are No Longer Automatically
Considered Dynamic

// ben

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