chicken-users
[Top][All Lists]
Advanced

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

Re: [Chicken-users] Chicken segfaults with large-ish inputs


From: Felix
Subject: Re: [Chicken-users] Chicken segfaults with large-ish inputs
Date: Sun, 20 Feb 2011 13:44:42 +0100 (CET)

From: Sam Hardwick <address@hidden>
Subject: [Chicken-users] Chicken segfaults with large-ish inputs
Date: Sat, 19 Feb 2011 23:47:42 +0200

> (define (sum term a next b)
>   (if (> a b)
>       0
>       (+ (term a)
>          (sum term (next a) next b))))
> 
> (define (adder n) (lambda (x) (+ x n)))
> 
> (define (integral f a b n)
>   (let ((h (/ (- b a) n)))
>     (define (y k) (f (+ a (* k h))))
>     (*
>      (/ h 3)
>      (+ a b
>       (* 4 (sum y 1 (adder 2) (- n 1)))
>       (* 2 (sum y 2 (adder 2) (- n 2)))))))
> 
> ***
> 
> When I exercise it with intervals divided into up to 100000 it works
> fine, but with eg.
> 
> ***
> 
> (define (cube x) (* x x x))
> (integral cube 0 1 1000000)

Ouch. This builds up an extremely deep chain of non-tail calls in
"sum" (I believe), which overflows the stack inside the interpreter
(when I compile the code, it seems to run ok - assumedly because the
stack usage is more efficient in compiled code). Stack checks (which
cause GC and thus reclamation of the stack) do not happen inside the
continuation calls done when the deep chain of calls to "+" return (if
this makes no sense to you, then nevermind, it barely makes sense to
me). I do not have a quick fix for this, but will try to find a
solution, which may be successful or maybe not.


cheers,
felix



reply via email to

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