From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Kevin Ryde Newsgroups: gmane.lisp.guile.devel Subject: Re: append! non-tail recursion Date: Thu, 15 Apr 2004 10:22:07 +1000 Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Message-ID: <87zn9ehyz4.fsf@zip.com.au> References: <87adbplt8j.fsf@zip.com.au> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: sea.gmane.org 1081988671 14180 80.91.224.253 (15 Apr 2004 00:24:31 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Thu, 15 Apr 2004 00:24:31 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Thu Apr 15 02:24:21 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1BDug1-0003xc-00 for ; Thu, 15 Apr 2004 02:24:21 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BDufu-00019g-1h for guile-devel@m.gmane.org; Wed, 14 Apr 2004 20:24:14 -0400 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.30) id 1BDuff-0000rr-5U for guile-devel@gnu.org; Wed, 14 Apr 2004 20:23:59 -0400 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.30) id 1BDueq-00084W-FN for guile-devel@gnu.org; Wed, 14 Apr 2004 20:23:41 -0400 Original-Received: from [61.8.0.84] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.30) id 1BDue6-0006kN-Ik for guile-devel@gnu.org; Wed, 14 Apr 2004 20:22:22 -0400 Original-Received: from mailproxy2.pacific.net.au (mailproxy2.pacific.net.au [61.8.0.87]) by mailout1.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i3F0MG4u004057 for ; Thu, 15 Apr 2004 10:22:16 +1000 Original-Received: from localhost (ppp270A.dyn.pacific.net.au [61.8.39.10]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-6.6) with ESMTP id i3F0MEsf026326 for ; Thu, 15 Apr 2004 10:22:15 +1000 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1BDudt-0000Jo-00; Thu, 15 Apr 2004 10:22:09 +1000 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110002 (No Gnus v0.2) Emacs/21.3 (gnu/linux) X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.4 Precedence: list List-Id: "Developers list for Guile, the GNU extensibility library" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.devel:3598 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:3598 I ended up with this change, * list.c (scm_append_x): Use iterative style, to avoid non-tail recursion. New code: SCM_DEFINE (scm_append_x, "append!", 0, 0, 1, (SCM lists), "A destructive version of @code{append} (@pxref{Pairs and\n" "Lists,,,r5rs, The Revised^5 Report on Scheme}). The cdr field\n" "of each list's final pair is changed to point to the head of\n" "the next list, so no consing is performed. Return\n" "the mutated list.") #define FUNC_NAME s_scm_append_x { SCM ret, *loc; SCM_VALIDATE_REST_ARGUMENT (lists); if (SCM_NULLP (lists)) return SCM_EOL; loc = &ret; for (;;) { SCM arg = SCM_CAR (lists); *loc = arg; lists = SCM_CDR (lists); if (SCM_NULLP (lists)) return ret; if (!SCM_NULL_OR_NIL_P (arg)) { SCM_VALIDATE_CONS (SCM_ARG1, arg); loc = SCM_CDRLOC (scm_last_pair (arg)); } } } #undef FUNC_NAME _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://mail.gnu.org/mailman/listinfo/guile-devel