Staying Out of Trouble

While lazy—and particularly unbounded— sequences are a powerful programming tool, dealing with them in the REPL has its issues. You certainly don’t want to try to print an entire infinite sequence, either explicitly, like this:

 user=>​ (​def​ numbers (iterate inc 1))
 #​'user/numbers
 
 user=>​ (println numbers) ​; Say goodnight!

or implicitly:

 user=>​ numbers ​; And that is it!

Never try to stare into the face of the infinite. This is where the *print-length* dynamic var and set!, both of which we saw back in Chapter 8, Def, Symbols, and Vars, come in handy:

 user=>​ (set! *print-length* 10)
 10
 
 user=>​ numbers
 (1 2 3 4 5 6 7 8 9 10 ...)

More subtly, you also need to be careful about side effects when ...

Get Getting Clojure now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.