[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: How to identify a potential memory leak in guile programs?
From: |
Hengqing Hu |
Subject: |
Re: How to identify a potential memory leak in guile programs? |
Date: |
Tue, 22 Jan 2013 23:09:00 +0800 |
After make it iterative, the fault disappears.
Many thanks to the help!
(define (enumerate-interval low high)
- (if (> low high)
- nil
- (cons low (enumerate-interval (+ low 1) high))))
+ (let loop ((i high)
+ (interval nil))
+ (if (< i low)
+ interval
+ (loop (- i 1) (cons i interval)))))
On Tue, Jan 22, 2013 at 7:14 PM, Thien-Thi Nguyen <address@hidden> wrote:
> () Hengqing Hu <address@hidden>
> () Tue, 22 Jan 2013 16:51:04 +0800
>
> Can somebody help to look into the code and tell me what's wrong?
>
> I don't know if this is the only problem, but certainly it contributes.
> The proc ‘enumerate-interval’ consumes stack unnnecessarily.
>
> guile> (enumerate-interval 3 500)
> ERROR: Stack overflow
> ABORT: (stack-overflow)
>
> Here is another implementation that doesn't have that problem.
>
> (define (enumerate-interval low high)
> (map (lambda (i)
> (+ i low))
> (iota (- high low -1))))
>
> --
> Thien-Thi Nguyen ..................................... GPG key: 4C807502
> . NB: ttn at glug dot org is not me .
> . (and has not been since 2007 or so) .
> . ACCEPT NO SUBSTITUTES .
> ........... please send technical questions to mailing lists ...........
--
Best Regards, Hengqing Hu