It is with the rest of the code as given here, because it is filter
which does the wrapping in lazy-seq
. If step
called itself, it would do all the filtering at once instead of lazily.
(Updated.) If lazy-seq
was added to step
's body, step
could then call itself and still be lazy. This could be accomplished at least in these two ways:
by wrapping the entire body in
lazy-seq
and replacing both the recursive call tofilter
and therecur
with calls tostep
; NB. in this case thestep
function would need to be named (either by replacing thelet
withletfn
, with the appropriate change in syntax, or by adding a name to thefn
form:(fn step ...)
); thelazy-seq
wrapping the outermost call tostep
would then be unnecessary; also, at this point you could simply not have an inner helper function (just use this approach infilter
directly);by leaving the
lazy-seq
infilter
in place and wrapping the recursive call instep
(which would now be tostep
itself) inlazy-seq
(with therecur
form remaining unchanged).
Note that clojure.core/filter
has a different implementation, with separate logic handling chunked sequences and no internal helper functions. In the non-chunked case it operates like the version of step
described in 1. above.