Programming Clojure, Fourth Edition: page 13 & 19

On page 13, how to make (require 'examples.introduction) work ? How to augment the CLASSPATH such that clj is able to find examples/introduction.clj ? TIA

1 Like

Based on what is written on page 19, the following arbitrary precision computation does not work. Is there a way to make it work ? And maybe indicate it in the book ?

user=> (/ 22.0 7)
3.142857142857143
user=> (/ 22.0M 7)
Execution error (ArithmeticException) at java.math.BigDecimal/divide (BigDecimal.java:1810).
Non-terminating decimal expansion; no exact representable decimal result.
1 Like

This is a bit beyond what we decided to cover in the book, but you can use the with-precision macro to indicate a specific precision (and optionally rounding mode) for bigdecimal computations:

user=> (with-precision 5 (/ 22.0M 7))
3.1429M
1 Like

I stumbled across the same problem. It would be sufficent to mpte that clj must be started in the directory code of the provided code examples, then everything will be found (because of the deps.edn file). I first startet clj in the src folder and then tried to add this directory to the classpath.

Thanks, I added a note in the Intro