On 24 Jan., 16:50, wubbie <sunj...@gmail.com> wrote:
> Hi,
>
> I wonder why self-call(filter) is used in one place and
> recur is used in the other.
>
> (defn filter
>   "Returns a lazy seq of the items in coll for which
>   (pred item) returns true. pred must be free of side-effects."
>   [pred coll]
>     (when (seq coll)
>       (if (pred (first coll))
>         (lazy-cons (first coll) (filter pred (rest coll)))   ;; filter
> *
>         (recur pred (rest coll)))))   ;; recur **


As the self-call to filter happens inside a lazy-cons the
stack is safe.
One can’t use recur here, because this call is not in the
tail position. It is a recursive non-tail call.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To post to this group, send email to clojure@googlegroups.com
To unsubscribe from this group, send email to 
clojure+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to