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: srfi-1 reduce Date: Sat, 12 Feb 2005 08:36:30 +1100 Message-ID: <87zmyaye1t.fsf@zip.com.au> NNTP-Posting-Host: main.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" X-Trace: sea.gmane.org 1108158147 26720 80.91.229.2 (11 Feb 2005 21:42:27 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 11 Feb 2005 21:42:27 +0000 (UTC) Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Fri Feb 11 22:42:26 2005 Original-Received: from lists.gnu.org ([199.232.76.165]) by ciao.gmane.org with esmtp (Exim 4.43) id 1CziYD-0004bO-Rr for guile-devel@m.gmane.org; Fri, 11 Feb 2005 22:42:10 +0100 Original-Received: from localhost ([127.0.0.1] helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1CzinE-0004a9-BR for guile-devel@m.gmane.org; Fri, 11 Feb 2005 16:57:40 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1CzimE-0004IS-V7 for guile-devel@gnu.org; Fri, 11 Feb 2005 16:56:39 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Czim2-0004E7-Vf for guile-devel@gnu.org; Fri, 11 Feb 2005 16:56:27 -0500 Original-Received: from [199.232.76.173] (helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Czim2-00049l-8i for guile-devel@gnu.org; Fri, 11 Feb 2005 16:56:26 -0500 Original-Received: from [61.8.0.84] (helo=mailout1.pacific.net.au) by monty-python.gnu.org with esmtp (Exim 4.34) id 1CziSt-0001qG-58 for guile-devel@gnu.org; Fri, 11 Feb 2005 16:36:39 -0500 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-7.1) with ESMTP id j1BLabA6032097 for ; Sat, 12 Feb 2005 08:36:37 +1100 Original-Received: from localhost (ppp2880.dyn.pacific.net.au [61.8.40.128]) by mailproxy2.pacific.net.au (8.12.3/8.12.3/Debian-7.1) with ESMTP id j1BLabGf029449 for ; Sat, 12 Feb 2005 08:36:37 +1100 Original-Received: from gg by localhost with local (Exim 3.36 #1 (Debian)) id 1CziSk-0000Re-00; Sat, 12 Feb 2005 08:36:30 +1100 Original-To: guile-devel@gnu.org Mail-Copies-To: never User-Agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3 (gnu/linux) 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 X-MailScanner-To: guile-devel@m.gmane.org Xref: main.gmane.org gmane.lisp.guile.devel:4770 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.devel:4770 --=-=-= * srfi-1.scm (reduce, reduce-right): Don't call f with ridentity, use it only if lst is empty, per srfi and intended optimization reduce represents over fold. --=-=-= Content-Disposition: inline; filename=srfi-1.scm.reduce.diff --- srfi-1.scm.~1.48.~ 2005-02-01 10:06:05.000000000 +1100 +++ srfi-1.scm 2005-02-11 21:11:00.000000000 +1100 @@ -511,10 +511,14 @@ (uf (g seed) (cons (f seed) lis)))))) (define (reduce f ridentity lst) - (fold f ridentity lst)) + (if (null? lst) + ridentity + (fold f (car lst) (cdr lst)))) (define (reduce-right f ridentity lst) - (fold-right f ridentity lst)) + (if (null? lst) + ridentity + (fold-right f (last lst) (drop-right lst 1)))) ;; Internal helper procedure. Map `f' over the single list `ls'. --=-=-= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Guile-devel mailing list Guile-devel@gnu.org http://lists.gnu.org/mailman/listinfo/guile-devel --=-=-=--