daveliepmann

daveliepmann

Programming Clojure, Third Edition: `assert` throws Error, not Exception (page 206-7)

@alexmiller

On page 206 to 207, my copy of Programming Clojure, Third Edition asserts the following:

assert tests an expression and raises an exception if it’s not logically true:

(assert (= 1 1))
 -> nil

 (assert (= 1 2))
 -> java.lang.Exception: Assert failed: (= 1 2)

This matches the assert docstring:

Evaluates expr and throws an exception if it does not evaluate to
logical true.

Unfortunately, it’s not so. assert raises an AssertionError, which is not an Exception. Reference Clojure source, ask Clojure question, JIRA ticket, REPL output:

$ clj
Clojure 1.11.1
user=> (assert (= 1 1))
nil
user=> (assert (= 1 2))
Execution error (AssertionError) at user/eval138 (REPL:1).
Assert failed: (= 1 2)
user=> (set! *assert* false)
false
user=> (assert (= 1 2))
nil

Perhaps the book’s REPL output predates this 2009 commit?

Marked As Solved

alexmiller

alexmiller

Author of Programming Clojure, Third Edition

The book and docstring say it “throws an exception” (a Java and Clojure language mechanism), not “throws Exception” (a specific Java class), so I think the statements are correct regardless.

Generally, the docstrings are careful about what they commit to, and there is no commitment here to a specific class.

Popular Prag Prog topics Top

iPaul
page 37 ANTLRInputStream input = new ANTLRInputStream(is); as of ANTLR 4 .8 should be: CharStream stream = CharStreams.fromStream(i...
New
mikecargal
Title: Hands-On Rust (Chap 8 (Adding a Heads Up Display) It looks like ​.with_simple_console_no_bg​(SCREEN_WIDTH*2, SCREEN_HEIGHT*2...
New
herminiotorres
Hi! I know not the intentions behind this narrative when called, on page XI: mount() |> handle_event() |> render() but the correc...
New
conradwt
First, the code resources: Page 237: rumbl_umbrella/apps/rumbl/mix.exs Note: That this file is missing. Page 238: rumbl_umbrella/app...
New
joepstender
The generated iex result below should list products instead of product for the metadata. (page 67) iex> product = %Product{} %Pento....
New
brunogirin
When trying to run tox in parallel as explained on page 151, I got the following error: tox: error: argument -p/–parallel: expected one...
New
New
creminology
Skimming ahead, much of the following is explained in Chapter 3, but new readers (like me!) will hit a roadblock in Chapter 2 with their ...
New
s2k
Hi all, currently I wonder how the Tailwind colours work (or don’t work). For example, in app/views/layouts/application.html.erb I have...
New
EdBorn
Title: Agile Web Development with Rails 7: (page 70) I am running windows 11 pro with rails 7.0.3 and ruby 3.1.2p20 (2022-04-12 revision...
New

Other popular topics Top

Devtalk
Hello Devtalk World! Please let us know a little about who you are and where you’re from :nerd_face:
New
siddhant3030
I’m thinking of buying a monitor that I can rotate to use as a vertical monitor? Also, I want to know if someone is using it for program...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
PragmaticBookshelf
A Hero’s Journey with Chris Pine @chrispine Chris Pine, author of Learn to Program, Third Edition, discusses his journey to beco...
New
Margaret
Hello everyone! This thread is to tell you about what authors from The Pragmatic Bookshelf are writing on Medium.
1127 25281 747
New
AstonJ
We’ve talked about his book briefly here but it is quickly becoming obsolete - so he’s decided to create a series of 7 podcasts, the firs...
New
PragmaticBookshelf
Author Spotlight Jamis Buck @jamis This month, we have the pleasure of spotlighting author Jamis Buck, who has written Mazes for Prog...
New
PragmaticBookshelf
Author Spotlight Erin Dees @undees Welcome to our new author spotlight! We had the pleasure of chatting with Erin Dees, co-author of ...
New
PragmaticBookshelf
Author Spotlight: Peter Ullrich @PJUllrich Data is at the core of every business, but it is useless if nobody can access and analyze ...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New

Latest in PragProg

View all threads ❯