guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: stack overflow problem


From: Stephen Compall
Subject: Re: stack overflow problem
Date: Sat, 04 Feb 2006 19:18:13 -0600

On Sat, 2006-02-04 at 18:54 +0800, William Xu wrote:
> (define (enumerate-interval low high)
>   "Return a sequence list by walking from LOW to HIGH.
> e.g.,
>         (enumerate-interval 1 10)
>                                  => (1 2 3 4 5 6 7 8 9 10)"
>   (if (> low high)
>       '()
>       (cons low (enumerate-interval (1+ low) high))))
> 
> When i passed it a slightly big interval, guile complains "stack
> overflow", 
> 
> 
> Might be a bug? (i also tested this on mzscheme, and works fine.)

Sorry, but while optimization of tail calls is guaranteed by R5RS,
non-tail recursion to arbitrary depth is not.  Try rewriting your code
so that the recursive call is the "last thing" done; to see what this
means, consider that in the recursion case, the "last thing" is
currently the call to cons.

See Section 33.3.7.1 (Stack overflow,
http://www.gnu.org/software/guile/docs/guile-ref/Debugger-options.html)
in the Guile Reference for details.

-- 
Stephen Compall
http://scompall.nocandysw.com/blog

Attachment: signature.asc
Description: This is a digitally signed message part


reply via email to

[Prev in Thread] Current Thread [Next in Thread]