From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludovic.courtes@laas.fr (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: New to the group... Date: Thu, 04 May 2006 15:08:51 +0200 Organization: LAAS-CNRS Message-ID: <87odye9bto.fsf@laas.fr> References: <9c4a82e00605032252u3687bb76ybe033f3c5de5d44b@mail.gmail.com> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1146748196 5670 80.91.229.2 (4 May 2006 13:09:56 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 4 May 2006 13:09:56 +0000 (UTC) Cc: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu May 04 15:09:55 2006 Return-path: Envelope-to: guile-devel@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1FbdaC-0001hB-Ty for guile-devel@m.gmane.org; Thu, 04 May 2006 15:09:29 +0200 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1FbdaC-0001bT-Cm for guile-devel@m.gmane.org; Thu, 04 May 2006 09:09:28 -0400 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Fbda7-0001bJ-VQ for guile-devel@gnu.org; Thu, 04 May 2006 09:09:23 -0400 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Fbda5-0001aE-2o for guile-devel@gnu.org; Thu, 04 May 2006 09:09:22 -0400 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Fbda4-0001aB-Ua for guile-devel@gnu.org; Thu, 04 May 2006 09:09:20 -0400 Original-Received: from [140.93.0.15] (helo=laas.laas.fr) by monty-python.gnu.org with esmtps (TLS-1.0:DHE_RSA_AES_256_CBC_SHA:32) (Exim 4.52) id 1Fbdag-0001fN-K2 for guile-devel@gnu.org; Thu, 04 May 2006 09:09:58 -0400 Original-Received: by laas.laas.fr (8.13.6/8.13.4) with SMTP id k44D9DIL021001; Thu, 4 May 2006 15:09:14 +0200 (CEST) Original-To: "Jason Meade" X-URL: http://www.laas.fr/~lcourtes/ X-Revolutionary-Date: 15 =?iso-8859-1?Q?Flor=E9al?= an 214 de la =?iso-8859-1?Q?R=E9volution?= X-PGP-Key-ID: 0xEB1F5364 X-PGP-Key: http://www.laas.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 821D 815D 902A 7EAB 5CEE D120 7FBA 3D4F EB1F 5364 X-OS: powerpc-unknown-linux-gnu Mail-Followup-To: "Jason Meade" , guile-devel@gnu.org In-Reply-To: <9c4a82e00605032252u3687bb76ybe033f3c5de5d44b@mail.gmail.com> (Jason Meade's message of "Wed, 3 May 2006 22:52:32 -0700") User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) X-Spam-Score: 0.633 () LARGE_HEX X-Scanned-By: MIMEDefang at CNRS-LAAS X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:5902 Archived-At: Hi, "Jason Meade" 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