guile-user
[Top][All Lists]
Advanced

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

Re: Stack Size?


From: Joshua Judson Rosen
Subject: Re: Stack Size?
Date: Mon, 5 Aug 2002 11:08:50 -0400
User-agent: Mutt/1.4i

On Mon, Aug 05, 2002 at 03:27:37AM -0600, Robert Uhl <address@hidden> wrote:
> I have the following empirical-integral function defined:
> 
> (define (integral func from to)
>   (define step (/ (- to from) 2048))
>   (define (my-int func from to)
>     (if (>= from to)
>       (func to)
>       (+ (func from) (my-int func (+ from step) to))))
>   (my-int func from to))
> 
> I recognise that this may not be the most attractive of ways to do it,
> but it should do the job.  Unfortunately, the following sequence of
> actions causes a stack overflow:
> 
> (define (q x) (- 10 (* 8 x)))
> (integral q 0 1.25)
> 
> How deep can guile's stack be?  This example does _not_ crash on
> umb-scheme, which is interesting.  Can anyone suggest a workaround?

I don't know about guile's stack-limitations, but I can suggest that
you write your function in a tail-recursive way, which would allow you
to avoid the stack, e.g.:

(define (integral func from to)
  (define step (/ (- to from) 2048))
  (define (my-int func from to base-value)
    (if (>= from to)
        (+ base-value (func to))
        (my-int func (+ from step) to (+ base-value (func from)))))
  (my-int func from to 0))



reply via email to

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