Programming Clojure sample code: fixes for breaking changes

37 views
Skip to first unread message

Stuart Halloway

unread,
Jan 16, 2009, 8:49:42 AM1/16/09
to clo...@googlegroups.com
Long, long ago (Tuesday) when Beta 5 of the book shipped, there were
some breakages in the sample code due to changes in clojure-contrib. I
believe everything is now fixed in the github repository (http://github.com/stuarthalloway/programming-clojure
).

Summary of the issues:

1. clojure.contrib.seq-util/includes? changed the argument order for
consistency with other operations. This caused problems with the
snippet web app; Compojure is now updated to match the change in
contrib.

2. clojure.contrib.sql/with-results has been removed and replaced with
with-query-results. This broke the snippet model. The code is now
fixed and I will update the prose in the next Beta.

3. A change to clojure.lang.Util necessitated a _clean_ rebuild of
contrib and compojure. I have rebuild these dependencies in the lib
directory.

4. A change to clojure.contrib.test-is.is broke a few unit tests. The
book doesn't reference any of these tests directly, but they are now
fixed in the code. You can run the whole test suite with ./runtests.sh.

Let me know if you find any other issues!

Thanks,
Stuart

Telman Yusupov

unread,
Jan 16, 2009, 9:49:34 AM1/16/09
to Clojure
I keep running into the following problem trying to supply agent
validation function. Here is sample code from page 135 (from book
version beta 5)

(use '[clojure.contrib.except :only (throw-if)])
(def counter (agent 0 #(throw-if (not (number? %)) "not a number")))

triggers the following exception:

java.lang.IllegalArgumentException: No value supplied for key: user
$fn__1197@89f302 (NO_SOURCE_FILE:2)
[Thrown class clojure.lang.Compiler$CompilerException]

I’m using the latest versions of clojure (r1216) and clojure-contrib
(r374) on Mac OS X 10.5.6, Java version "1.5.0_16"

Many thanks,

Telman

Stuart Halloway

unread,
Jan 16, 2009, 10:02:03 AM1/16/09
to clo...@googlegroups.com
Hi Telman,

The signature for agent has changed. Use:

(def counter (agent 0 :validator number?))

I will update the prose in Beta 6.

Stuart

Telman Yusupov

unread,
Jan 16, 2009, 10:37:46 AM1/16/09
to Clojure
Thank you very much, Stuart!

I think it's a good idea for me to start reading Clojure source code
and keep track of the changes, as the language changes so quickly...


On Jan 16, 10:02 am, Stuart Halloway <stuart.hallo...@gmail.com>

Joshua Fox

unread,
Jan 24, 2009, 3:46:38 PM1/24/09
to clo...@googlegroups.com
A related point about the validator function (for Refs), possible the result of the same change in the  Clojure codebase
On page 133 of Beta 5.0, 

    (def messages (ref () :validator  validate-message-list)

The code samples, using, the  bundled clojure, do work. However, right above the code on p. 133, the keyword :validate is given instead.

Using the Clojure release of Dec. 17, that line of code does not work. I get to it work by eliminating the :validator keyword and passing the function as an additional parameter; following this documentation http://clojure.org/api#toc434

Joshua

Stuart Halloway

unread,
Jan 24, 2009, 5:24:28 PM1/24/09
to clo...@googlegroups.com
Thanks Joshua,

This is fixed in the next beta.

Stuart

Reply all
Reply to author
Forward
0 new messages