Deal of the Day

Home » Main » Manning Forums » 2009 » Clojure in Action

Thread: Errors and Corrections

Reply to this Thread Reply to this Thread Search Forum Search Forum Back to Thread List Back to Thread List

Permlink Replies: 43 - Pages: 3 [ Previous | 1 2 3 ] - Last Post: Feb 7, 2013 9:55 PM by: catalan42
jromine

Posts: 2
From: Sandy, UT
Registered: 2/6/12
Re: Errors and Corrections
Posted: Feb 6, 2012 11:13 PM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

You're probably already aware of this but 1.3 requires the the ^:dynamic meta-data take for vars whose bindings are changed dynamically. Listing 3.4, for instance, doesn't work as is. Reference:

https://groups.google.com/forum/?fromgroups#!msg/clojure/vOL8MSOhp1M/wv5iSpK4FxsJ

jromine

Posts: 2
From: Sandy, UT
Registered: 2/6/12
Re: Errors and Corrections
Posted: Feb 7, 2012 12:14 AM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

Sorry if this is a repeat.

Listing 3.7 doesn't work due to incompatibilities between org.danlarkin/clojure-json and Clojure 1.3. See:

https://groups.google.com/forum/#!topic/clojure/lz-uFmukEh0

Solution seems to be to use [org.clojure/data.json "0.1.1"]

ngroot

Posts: 1
From: New York, NY
Registered: 4/29/12
Re: Errors and Corrections
Posted: Apr 29, 2012 4:02 PM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

p.211

redis-clojure is no longer maintained by ragnard. It's been picked up by tavisrudd; the new URL is https://github.com/tavisrudd/redis-clojure .

Also, the core namespace for redis-clojure is now redis.core, not redis.

essin@ieee.org

Posts: 3
Registered: 6/6/12
Re: Errors and Corrections
Posted: Sep 22, 2012 4:06 PM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

in 2.1.3

(def users {"kyle" {:password "secretk" :number-pets 2}
"siva" {:password "secrets" :number-pets 4}
"rob" {:password "secretr" :number-pets 6}
"george" {:password "secretg" :number-pets 8}})
Now we can write a function that will decide if credentials are correct. It will accept a username and a password and then check to see if the associated user is valid:

(defn check-login [username password]
(let [actual-password ((users username) :password)]
(= actual-password password)))
The function is called check-login, and it takes two arguments, username and password. It does a simple check against our database of user information. You can ignore the let form for now; it’s used to introduce the local name actual-password; we’ll visit it again in the next section on program structure. We’ll also show how to use maps and symbols toward the latter part of this chapter. Let’s try check-login at the REPL:

user=> (check-login "siva" "secrets")
true

user=> (check-login "amit" "blah")
false

--> last command does not eval to false. There is no amit entry in the data.
you get:
user=> (check-login "amit" "blah")
NullPointerException user/check-login (NO_SOURCE_FILE:2)

Message was edited by:
essin@ieee.org

Gonzih

Posts: 1
Registered: 10/19/12
Re: Errors and Corrections
Posted: Oct 19, 2012 2:55 AM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

p. 119
Table 5.1

:implements - A vector of classes (should be interfaces) that the class implements.

mpettis

Posts: 4
From: Minneapolis, MN
Registered: 1/10/12
Re: Errors and Corrections
Posted: Jan 12, 2013 11:11 PM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

I think that on p51 on thread-first, this:

(* (Math/pow (+ 1 (/ rate 100)) time-periods) principle)

should be this:

(* (Math/pow (+ (/ rate 100) 1) time-periods) principle)

same result, but you are explaining how threading substitutes arguments into the second positon, and I believe the second sexp here conforms with the rules and the first one you have above does not. Not sure, but I think I am right...

Message was edited by:
mpettis

pbwest

Posts: 3
Registered: 1/20/13
Re: Errors and Corrections
Posted: Jan 20, 2013 1:32 AM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

Page 10
The combination of these three notations—parentheses, square brackets, and braces— makes Clojure easy to read when compared to other Common Lisp or Scheme.

...either Common Lisp or Scheme.

dmelikov

Posts: 2
Registered: 1/24/13
Re: Errors and Corrections
Posted: Jan 24, 2013 10:15 PM   in response to: luke.bace in response to: luke.bace
  Click to reply to this thread Reply

p.76: running code from listing 3.4 produces following output:

Warning: *eval-me* not declared dynamic and thus is not dynamically rebindable, but its name suggests otherwise. Please either indicate ^:dynamic *eval-me* or change the name. (clojureproject\core.clj:21)
A: 10
IllegalStateException Can't dynamically bind non-dynamic var: clojureproject.core/*eval-me* clojure.lang.Var.pushThreadBindings (Var.java:353)

Add ^:dynamic to the declaration to fix the problem:

(def ^:dynamic *eval-me* 10)

dmelikov

Posts: 2
Registered: 1/24/13
Re: Errors and Corrections
Posted: Jan 25, 2013 2:29 PM   in response to: dmelikov in response to: dmelikov
  Click to reply to this thread Reply

Same problem with listing 3.5 on p.76:

This is the fix: (defn ^:dynamic twice [x] ...

catalan42

Posts: 31
From: San Diego, CA
Registered: 2/16/07
Re: Errors and Corrections
Posted: Feb 6, 2013 10:05 PM   in response to: dmelikov in response to: dmelikov
  Click to reply to this thread Reply

page 47, first code block uses both run-report and run-reports (should be same)

catalan42

Posts: 31
From: San Diego, CA
Registered: 2/16/07
Re: Errors and Corrections
Posted: Feb 6, 2013 10:20 PM   in response to: catalan42 in response to: catalan42
  Click to reply to this thread Reply

Chapter 2, page 51, 2nd code block: the expansion of the + function should be (+ (/ rate 100) 1) since it is thread-first.

catalan42

Posts: 31
From: San Diego, CA
Registered: 2/16/07
Re: Errors and Corrections
Posted: Feb 6, 2013 10:43 PM   in response to: catalan42 in response to: catalan42
  Click to reply to this thread Reply

Chapter 3, page 63, line 2: "hash" should be "map" (or at least "hashmap")

catalan42

Posts: 31
From: San Diego, CA
Registered: 2/16/07
Re: Errors and Corrections
Posted: Feb 6, 2013 11:14 PM   in response to: catalan42 in response to: catalan42
  Click to reply to this thread Reply

Chapter 3, page 75, paragraph 2: "let's use test this" -> "let's test this"

catalan42

Posts: 31
From: San Diego, CA
Registered: 2/16/07
Re: Errors and Corrections
Posted: Feb 7, 2013 9:55 PM   in response to: catalan42 in response to: catalan42
  Click to reply to this thread Reply

Chapter 6, page 145, last paragraph: "the threading asking for" -> "the thread asking for"

Legend
Gold: 300 + pts
Silver: 100 - 299 pts
Bronze: 25 - 99 pts
Manning Author
Manning Staff
Manning Developmental Editor