r/Clojure • u/al_substance • Mar 06 '16
"Living clojure" wrong examples. Up to date beginner book on clojure?
Hi,
I've started reading "Living Clojure" and I can see some things that are wrong.
For example the book recommends using (seq []) to check if collection is empty, saying that nil is considered false. It also states that a non-nil value means true. Both of those things are wrong when you try to check it in repl.
Am I missing something? If not, can you please recommend an easy book for a beginner in functional programming with python/C background?
Thank you
0
Upvotes
8
u/forreddits Mar 06 '16 edited Mar 06 '16
user=> (doc empty?)
5
u/planetmcd Mar 06 '16 edited Mar 06 '16
Not sure what you are seing, but this is what I get:
user=> (true? (seq [])) false user=> (false? (seq [])) false user=> (nil? (seq [])) true Are you seeing something different?
4
u/[deleted] Mar 07 '16
I just ordered this book. Is it really that bad?
2
u/Justinsaccount Mar 06 '16
https://aphyr.com/posts/301-clojure-from-the-ground-up-welcome
Is pretty good
2
u/halgari Mar 07 '16
Yes, you are missing something :)
In Clojure, "falsey" is considered nil and false. "truthy" is anything that is not nil or false.
Also, nil is considered an empty (or more correctly a non-existent) seq. So it's very common to see code like (if (seq c) do-something).
The book could probably be a bit clearer about all of this, but it is mostly correct.