laughingboy (11) [Avatar] Offline
#1
(dorun (rec-step (range 200000)))
;=> java.lang.StackOverflowError

This example overflows the stack without the dorun.
Chouser (21) [Avatar] Offline
#2
Re: What is the purpose of the dorun on p. 158?
Thanks for trying out our examples. And it's a good question...

We're just being explicit about forcing the whole seq. The only reason an exception
may be thrown without 'dorun' is if the REPL tries to print the entire seq. It is common to have settings that prevent this and thus would cause this example to act differently.
laughingboy (11) [Avatar] Offline
#3
Re: What is the purpose of the dorun on p. 158?
I'm still a bit confused. I understand the "repl forces realization of a lazy sequence" phenomenon, but my understanding from the definition of rec-step is that it will not be lazy even if the input is a lazy sequence, i.e., (type (range 10)) is a lazy sequence but (type (rec-step (range 10))) is a persistent vector which is not lazy.

So when you say "We can use the dorun function to traverse a lazy sequence and force the evaluation of each element", that's a true statement about dorun. However, (rec-step (range 200000)) isn't a lazy sequence, correct?
Chouser (21) [Avatar] Offline
#4
Re: What is the purpose of the dorun on p. 158?
You're absolutely right. rec-step is not lazy, and dorun is doing nothing here. Probably the example evolved and parts got left that didn't belong. Thanks for catching this, we'll fix it.