On Thu, Dec 1, 2011 at 7:03 AM, John Holland <jbholl...@gmail.com> wrote:

> I've been looking into Clojure and now Scheme for a while. Currently
> it's been SICP.
>
> I notice that SICP has examples of recursion such as a binary tree
> builder that is something like the following:
>
> (define (tree top elements split-value)
> (cons (tree  (filter (< split-value)  elements) )
>           (tree (filter (>=  split-value) elements )))
> ))
>
>
> This is just something I threw in here and is not real code. The point
> is that tree makes two calls to itself.
> For a large number of elements, there will be approx ((log base 2)
> elements) recursive calls to "tree".
>
> In clojure, would this be possible? Wouldn't it produce a stack overflow
> with big enough input? Would there be a way to define it in terms of
> recur, loop, etc?
>
>
> Apologies if this is too obvious.......
> John Holland
>

This will also grow the stack in Scheme. Writing tail recursive code is
more natural in Scheme that is certain. However I've found few cases that
cannot be solved in well in Clojure (and with good performance) with recur,
trampoline, or lazy sequences.

David

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
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