unofficial mirror of bug-guile@gnu.org 
 help / color / mirror / Atom feed
* guile-tutorial does not know bounded stack size
@ 2002-07-12 12:42 Dr. M. Luedde
  2002-07-13  0:09 ` Neil Jerram
  0 siblings, 1 reply; 2+ messages in thread
From: Dr. M. Luedde @ 2002-07-12 12:42 UTC (permalink / raw)


Hello!

The guile-tutorial provides an example calculating the factorial of
500.

The non-tail-recursive version from the tutorial yields a stack
overflow on my system. A tail-recursive implementation works.

Cheers, Mirko. 

D:\tmp>uname -a
uname -a
CYGWIN_NT-5.0 XPERT8302 1.3.12(0.54/3/2) 2002-07-06 02:16 i686 unknown

D:\tmp>guile
guile
guile> (version)
"1.5.6"
guile> (define (fac n) (if (= n 0) 1 (* n (fac (- n 1)))))
guile> (fac 500)
ERROR: Stack overflow
ABORT: (stack-overflow)
guile> (define (fac2 n) (define (h k l) (if (zero? k) l (h (- k 1) (* k l)))) (h n 1))
guile> (fac2 500)
122013682599111006870123878542304692625357434280319284219241358838584537315388199760549644750220328186301361647714820358416337872207817720048078520515932928547790757193933060377296085908627042917454788242491272634430567017327076946106280231045264421887878946575477714986349436778103764427403382736539747138647787849543848959553753799042324106127132698432774571554630997720278101456108118837370953101635632443298702956389662891165897476957208792692887128178007026517450776841071962439039432253642260523494585012991857150124870696156814162535905669342381300885624924689156412677565448188650659384795177536089400574523894033579847636394490531306232374906644504882466507594673586207463792518420045936969298102226397195259719094521782333175693458150855233282076282002340262690789834245171200620771464097945611612762914595123722991334016955236385094288559201872743379517301458635757082835578015873543276888868012039988238470215146760544540766353598417443048012893831389688163948746965881750450692
6365338175055478128640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
guile> 


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


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

* Re: guile-tutorial does not know bounded stack size
  2002-07-12 12:42 guile-tutorial does not know bounded stack size Dr. M. Luedde
@ 2002-07-13  0:09 ` Neil Jerram
  0 siblings, 0 replies; 2+ messages in thread
From: Neil Jerram @ 2002-07-13  0:09 UTC (permalink / raw)
  Cc: bug-guile

>>>>> "M" == M Luedde <Mirko.Luedde@Computer.Org> writes:

    M> Hello!
    M> The guile-tutorial provides an example calculating the factorial of
    M> 500.

    M> The non-tail-recursive version from the tutorial yields a stack
    M> overflow on my system. A tail-recursive implementation works.

Many thanks for the report.  However, this is broadly a feature, not a
bug.  Unless you think that Guile should have an unlimited stack size,
a non-tail-recursive factorial will always overflow the stack for a
big enough number.

You can examine and increase Guile's stack limit like this:

guile> (debug-options 'full)
show-file-name	#t	Show file names and line numbers in backtraces when not `#f'.  A value of `base' displays only base names, while `#t' displays full names.
stack		20000	Stack size limit (measured in words; 0 = no check).
debug		yes	Use the debugging evaluator.
backtrace	yes	Show backtrace on error.
depth		20	Maximal length of printed backtrace.
maxdepth	1000	Maximal number of stored backtrace frames.
frames		3	Maximum number of tail-recursive frames in backtrace.
indent		10	Maximal indentation in backtrace.
width		79	Maximal width of backtrace.
backwards	no	Display backtrace in anti-chronological order.
procnames	yes	Record procedure names at definition.
trace		no	*Trace mode.
breakpoints	no	*Check for breakpoints.
cheap		yes	*Flyweight representation of the stack at traps.
guile> (debug-set! stack 200000)
(show-file-name #t stack 200000 debug backtrace depth 20 maxdepth 1000 frames 3 indent 10 width 79 procnames cheap)
guile> (fac 500)
12201368259911100687012387854230469262535743428031928421924135883858453731538819976054964475022032818630136164771482035841633787220781772004807852051593292854779075719393306037729608590862704291745478824249127263443056701732707694610628023104526442188787894657547771498634943677810376442740338273653974713864778784954384895955375379904232410612713269843277457155463099772027810145610811883737095310163563244329870295638966289116589747695720879269288712817800702651745077684107196243903943225364226052349458501299185715012487069615681416253590566934238130088562492468915641267756544818865065938479517753608940057452389403357984763639449053130623237490664450488246650759467358620746379251842004593696929810222639719525971909452178233317569345815085523328207628200234026269078983424517120062077146409794561161276291459512372299133401695523638509428855920187274337951730145863575708283557801587354327688886801203998823847021514676054454076635359841744304801289383138968816394874696588175045069!

26365338175055478128640000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
guile> 

Is this OK, or do you think the documentation needs improving
somewhere?  (If you do, it would be most helpful if you could suggest
a patch ...)

        Neil


_______________________________________________
Bug-guile mailing list
Bug-guile@gnu.org
http://mail.gnu.org/mailman/listinfo/bug-guile


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

end of thread, other threads:[~2002-07-13  0:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-12 12:42 guile-tutorial does not know bounded stack size Dr. M. Luedde
2002-07-13  0:09 ` Neil Jerram

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).