unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* stack overflow problem
@ 2006-02-04 10:54 William Xu
  2006-02-04 23:03 ` Chusslove Illich
  2006-02-05  1:18 ` Stephen Compall
  0 siblings, 2 replies; 6+ messages in thread
From: William Xu @ 2006-02-04 10:54 UTC (permalink / raw)


Hi, 

I define the following function, 

(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", 

guile > (enumerate-interval 1 400)
...
guile > (enumerate-interval 1 500)
ERROR: Stack overflow
ABORT: (stack-overflow)
guile> 

Might be a bug? (i also tested this on mzscheme, and works fine.)

Guile version: 1.6.7, debian unstable.

-- 
William


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* stack overflow problem
@ 2006-02-04 17:09 William Xu
  0 siblings, 0 replies; 6+ messages in thread
From: William Xu @ 2006-02-04 17:09 UTC (permalink / raw)


[i wish i'm not resending this mail..]

Hi,

I define the following function,

(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",

guile > (enumerate-interval 1 400)
...
guile > (enumerate-interval 1 500)
ERROR: Stack overflow
ABORT: (stack-overflow)
guile>

Might be a bug? (i also tested this on mzscheme, and works fine.)

Guile version: 1.6.7, debian unstable.

-- 
William


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: stack overflow problem
  2006-02-04 10:54 stack overflow problem William Xu
@ 2006-02-04 23:03 ` Chusslove Illich
  2006-02-05  1:18 ` Stephen Compall
  1 sibling, 0 replies; 6+ messages in thread
From: Chusslove Illich @ 2006-02-04 23:03 UTC (permalink / raw)



[-- Attachment #1.1: Type: text/plain, Size: 594 bytes --]

> [: William Xu :]
> Might be a bug? (i also tested this on mzscheme, and works fine.)
>
> Guile version: 1.6.7, debian unstable.

Same Debian, same Guile, same effect. I guess stack has to go at one point 
or another, and it is anyway a better idea to use tail recursion:

(define (enumerate-interval low high)
  (letrec ((helper
             (lambda (low high seq)
                     (if (> low high)
                         seq
                         (helper low (1- high) (cons high seq))))))
    (helper low high '())))

-- 
Chusslove Illich (Часлав Илић)

[-- Attachment #1.2: Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: stack overflow problem
  2006-02-04 10:54 stack overflow problem William Xu
  2006-02-04 23:03 ` Chusslove Illich
@ 2006-02-05  1:18 ` Stephen Compall
  2006-02-05 14:08   ` William Xu
  1 sibling, 1 reply; 6+ messages in thread
From: Stephen Compall @ 2006-02-05  1:18 UTC (permalink / raw)
  Cc: guile-user


[-- Attachment #1.1: Type: text/plain, Size: 1036 bytes --]

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 #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: stack overflow problem
  2006-02-05  1:18 ` Stephen Compall
@ 2006-02-05 14:08   ` William Xu
  2006-02-13 18:08     ` Holger Blasum
  0 siblings, 1 reply; 6+ messages in thread
From: William Xu @ 2006-02-05 14:08 UTC (permalink / raw)


Stephen Compall <s11@member.fsf.org> writes:

> 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; 

Yeah, i understand that. But i thought this ought to be done
automatically in some way, not requiring user to do this manually, which
would make codes less readable, isn't it?

[...]

-- 
William


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: stack overflow problem
  2006-02-05 14:08   ` William Xu
@ 2006-02-13 18:08     ` Holger Blasum
  0 siblings, 0 replies; 6+ messages in thread
From: Holger Blasum @ 2006-02-13 18:08 UTC (permalink / raw)
  Cc: guile-user


[-- Attachment #1.1: Type: text/plain, Size: 380 bytes --]

On 02-05, William Xu wrote:
> Yeah, i understand that. But i thought this ought to be done
> automatically in some way, not requiring user to do this manually, which
> would make codes less readable, isn't it?

(debug-set! stack 0) 

would do the trick (disabling stack depth management) afaik?

-- 
Holger Blasum +49-174-7313590 (gsm) GnuPG 1024D/ACDFC3B769DC1ED66B47

[-- Attachment #1.2: Digital signature --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://lists.gnu.org/mailman/listinfo/guile-user

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2006-02-13 18:08 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2006-02-04 10:54 stack overflow problem William Xu
2006-02-04 23:03 ` Chusslove Illich
2006-02-05  1:18 ` Stephen Compall
2006-02-05 14:08   ` William Xu
2006-02-13 18:08     ` Holger Blasum
  -- strict thread matches above, loose matches on Subject: below --
2006-02-04 17:09 William Xu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).