unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: ludovic.courtes@laas.fr (Ludovic Courtès)
Cc: guile-devel@gnu.org
Subject: Re: New to the group...
Date: Thu, 04 May 2006 15:08:51 +0200	[thread overview]
Message-ID: <87odye9bto.fsf@laas.fr> (raw)
In-Reply-To: <9c4a82e00605032252u3687bb76ybe033f3c5de5d44b@mail.gmail.com> (Jason Meade's message of "Wed, 3 May 2006 22:52:32 -0700")

Hi,

"Jason Meade" <jemeade@gmail.com> writes:

> (define fact
>  (lambda (n)
>    (cond
>     ((= n 1) 1)
>     (else
>      (* n (fact (- n 1)))))))
>
> guile> (fact 69)
> 171122452428141311372468338881272839092270544893520369393648040923257279754140647424000000000000000
> guile> (fact 70)
> ERROR: Stack overflow
> ABORT: (stack-overflow)

Your definition of `fact' is not tail-recursive, i.e., for each
recursive call, a new stack frame is created.  In order to remove this
problem, you have to rewrite `fact' so that it is tail-recursive (which
means that the function returns immediately after the recursive call):
this way Guile will not create any new stack frame for the recursive
calls.

See for instance the definition of `tail-factorial' there:
http://sourceware.org/ml/guile/2000-06/msg00074.html .

Thanks,
Ludovic.


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


  parent reply	other threads:[~2006-05-04 13:08 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2006-05-04  5:52 New to the group Jason Meade
2006-05-04  6:33 ` David Pirotte
2006-05-04 13:08 ` Ludovic Courtès [this message]
2006-05-04 15:57 ` Neil Jerram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87odye9bto.fsf@laas.fr \
    --to=ludovic.courtes@laas.fr \
    --cc=guile-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).