Re: Fail to run dynamic binding code with Clojure1.4

2012-10-30 Thread Satoru Logic
Thanks

On Wednesday, October 31, 2012 12:41:24 PM UTC+8, Sean Corfield wrote:
>
> On Tue, Oct 30, 2012 at 8:38 PM, Satoru Logic 
> > 
> wrote: 
> > Could you please recommend a book that's more up-to-date? 
>
> Clojure Programming http://www.clojurebook.com/ would be my first choice. 
>
> Programming Clojure 2nd Edition 
> http://pragprog.com/book/shcloj2/programming-clojure would be my 
> second choice. 
>
> The Joy of Clojure http://manning.com/fogus/ is an older book but is 
> more high-level - the "why" of functional programming - so it's still 
> applicable to more recent Clojure versions, but definitely a book for 
> when you have more Clojure under your belt. 
> -- 
> Sean A Corfield -- (904) 302-SEAN 
> An Architect's View -- http://corfield.org/ 
> World Singles, LLC. -- http://worldsingles.com/ 
>
> "Perfection is the enemy of the good." 
> -- Gustave Flaubert, French realist novelist (1821-1880) 
>

-- 
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: Fail to run dynamic binding code with Clojure1.4

2012-10-30 Thread Sean Corfield
On Tue, Oct 30, 2012 at 8:38 PM, Satoru Logic  wrote:
> Could you please recommend a book that's more up-to-date?

Clojure Programming http://www.clojurebook.com/ would be my first choice.

Programming Clojure 2nd Edition
http://pragprog.com/book/shcloj2/programming-clojure would be my
second choice.

The Joy of Clojure http://manning.com/fogus/ is an older book but is
more high-level - the "why" of functional programming - so it's still
applicable to more recent Clojure versions, but definitely a book for
when you have more Clojure under your belt.
-- 
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/

"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)

-- 
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: Fail to run dynamic binding code with Clojure1.4

2012-10-30 Thread Satoru Logic
Does this mean vars are dynamic by default prior to Clojure1.3, and lexical 
afterwards?

On Wednesday, October 31, 2012 9:36:47 AM UTC+8, Andy Fingerhut wrote:
>
> The code works as written in Clojure 1.2 and 1.2.1.
>
> It doesn't in 1.3 and later, unless you change the definition of twice to 
> annotate that it is a dynamic var, like so:
>
> (defn ^:dynamic twice [x]
>   (println "original function")
>   (* 2 x))
>
> With that change, it works in Clojure 1.3 and later.
>
> Andy
>
>
> On Oct 30, 2012, at 5:42 PM, Satoru Logic wrote:
>
> Hi, all.
>
> I am reading Clojure in Action.
>
> In the "scope" section of Chapter3, there are examples like this:
>
>   defn twice [x]
>   (println "original function")
>   (* 2 x))
>
> (defn call-twice [y]
>   (twice y))
>
> (defn with-log [function-to-call log-statement]
>   (fn [& args]
>
> (println log-statement)
> (apply function-to-call args)))
>
> (call-twice 10)
>
> (binding [twice (with-log twice "Calling the twice function")]
>(call-twice 20))
>
> (call-twice 30)
>
>
> When I tried to run this code in repl, I got the following exception:
>
>
> IllegalStateException Can't dynamically bind non-dynamic var: user/twice 
>> clojure.lang.Var.pushThreadBindings (Var.java:353)
>
>
> Is the book wrong or I'm running with the wrong version of clojure? 
>
>

-- 
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: Fail to run dynamic binding code with Clojure1.4

2012-10-30 Thread Satoru Logic
Could you please recommend a book that's more up-to-date?

On Wednesday, October 31, 2012 11:26:48 AM UTC+8, Sean Corfield wrote:
>
> Yes, it's very unfortunate that Manning released Clojure in Action 
> without a final pass to make it Clojure 1.3 compatible. I talked to 
> them about it when they still had time to make changes but they 
> decided to go ahead and publish a book that is tightly wedded to 
> Clojure 1.2 after Clojure 1.3 had been released. I think it was a 
> disservice to both the author and the community :( 
>
> Sean 
>
> On Tue, Oct 30, 2012 at 6:36 PM, Andy Fingerhut 
> > wrote: 
> > The code works as written in Clojure 1.2 and 1.2.1. 
> > 
> > It doesn't in 1.3 and later, unless you change the definition of twice 
> to 
> > annotate that it is a dynamic var, like so: 
> > 
> > (defn ^:dynamic twice [x] 
> >   (println "original function") 
> >   (* 2 x)) 
> > 
> > With that change, it works in Clojure 1.3 and later. 
> > 
> > Andy 
>

-- 
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: Fail to run dynamic binding code with Clojure1.4

2012-10-30 Thread Sean Corfield
Yes, it's very unfortunate that Manning released Clojure in Action
without a final pass to make it Clojure 1.3 compatible. I talked to
them about it when they still had time to make changes but they
decided to go ahead and publish a book that is tightly wedded to
Clojure 1.2 after Clojure 1.3 had been released. I think it was a
disservice to both the author and the community :(

Sean

On Tue, Oct 30, 2012 at 6:36 PM, Andy Fingerhut
 wrote:
> The code works as written in Clojure 1.2 and 1.2.1.
>
> It doesn't in 1.3 and later, unless you change the definition of twice to
> annotate that it is a dynamic var, like so:
>
> (defn ^:dynamic twice [x]
>   (println "original function")
>   (* 2 x))
>
> With that change, it works in Clojure 1.3 and later.
>
> Andy

-- 
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: Fail to run dynamic binding code with Clojure1.4

2012-10-30 Thread Andy Fingerhut
The code works as written in Clojure 1.2 and 1.2.1.

It doesn't in 1.3 and later, unless you change the definition of twice to 
annotate that it is a dynamic var, like so:

(defn ^:dynamic twice [x]
  (println "original function")
  (* 2 x))

With that change, it works in Clojure 1.3 and later.

Andy


On Oct 30, 2012, at 5:42 PM, Satoru Logic wrote:

> Hi, all.
> 
> I am reading Clojure in Action.
> 
> In the "scope" section of Chapter3, there are examples like this:
> 
> defn twice [x]
>   (println "original function")
>   (* 2 x))
> (defn call-twice [y]
>   (twice y))
> (defn with-log [function-to-call log-statement]
>   (fn [& args]
> (println log-statement)
> (apply function-to-call args)))
>   
> (call-twice 10)
>   
> (binding [twice (with-log twice "Calling the twice function")]
>(call-twice 20))
>   
> (call-twice 30)
> 
> When I tried to run this code in repl, I got the following exception:
> 
> IllegalStateException Can't dynamically bind non-dynamic var: user/twice  
> clojure.lang.Var.pushThreadBindings (Var.java:353)
> 
> Is the book wrong or I'm running with the wrong version of clojure? 

-- 
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: Fail to run dynamic binding code with Clojure1.4

2012-10-30 Thread gaz jones
As of Clojure 1.3 you need to mark things you with to re-bind
explicitly as dynamic:

(defn ^:dynamic twice [x]
  ...)


On Tue, Oct 30, 2012 at 7:42 PM, Satoru Logic  wrote:
> Hi, all.
>
> I am reading Clojure in Action.
>
> In the "scope" section of Chapter3, there are examples like this:
>
> defn twice [x]
>   (println "original function")
>   (* 2 x))
>
> (defn call-twice [y]
>   (twice y))
>
> (defn with-log [function-to-call log-statement]
>   (fn [& args]
>
> (println log-statement)
> (apply function-to-call args)))
>
>   
>
> (call-twice 10)
>
>   
>
> (binding [twice (with-log twice "Calling the twice function")]
>(call-twice 20))
>
>   
>
> (call-twice 30)
>
>
> When I tried to run this code in repl, I got the following exception:
>
>
>> IllegalStateException Can't dynamically bind non-dynamic var: user/twice
>> clojure.lang.Var.pushThreadBindings (Var.java:353)
>
>
> Is the book wrong or I'm running with the wrong version of clojure?
>
>   
>   
>   
>   
>
> --
> 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