From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Mark H Weaver Newsgroups: gmane.lisp.guile.bugs Subject: bug#17485: (srfi srfi-1) reduce-right does not scale, version 2.0.9 Date: Sun, 01 Jun 2014 19:41:41 -0400 Message-ID: <87r4382o5m.fsf@yeeloong.lan> References: <87y4y6t0or.fsf@fencepost.gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: ger.gmane.org 1401666208 18610 80.91.229.3 (1 Jun 2014 23:43:28 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sun, 1 Jun 2014 23:43:28 +0000 (UTC) Cc: 17485@debbugs.gnu.org To: David Kastrup Original-X-From: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Mon Jun 02 01:43:22 2014 Return-path: Envelope-to: guile-bugs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1WrFPN-00071g-Pl for guile-bugs@m.gmane.org; Mon, 02 Jun 2014 01:43:21 +0200 Original-Received: from localhost ([::1]:42358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrFPN-0006Ic-Ct for guile-bugs@m.gmane.org; Sun, 01 Jun 2014 19:43:21 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:36890) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrFPF-0006Ek-SQ for bug-guile@gnu.org; Sun, 01 Jun 2014 19:43:19 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WrFP5-0007cs-Ai for bug-guile@gnu.org; Sun, 01 Jun 2014 19:43:13 -0400 Original-Received: from debbugs.gnu.org ([140.186.70.43]:41249) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WrFP5-0007co-5s for bug-guile@gnu.org; Sun, 01 Jun 2014 19:43:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.80) (envelope-from ) id 1WrFP4-0007xo-He for bug-guile@gnu.org; Sun, 01 Jun 2014 19:43:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Mark H Weaver Original-Sender: "Debbugs-submit" Resent-CC: bug-guile@gnu.org Resent-Date: Sun, 01 Jun 2014 23:43:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 17485 X-GNU-PR-Package: guile X-GNU-PR-Keywords: Original-Received: via spool by 17485-submit@debbugs.gnu.org id=B17485.140166612230531 (code B ref 17485); Sun, 01 Jun 2014 23:43:02 +0000 Original-Received: (at 17485) by debbugs.gnu.org; 1 Jun 2014 23:42:02 +0000 Original-Received: from localhost ([127.0.0.1]:40126 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WrFO5-0007wM-Lj for submit@debbugs.gnu.org; Sun, 01 Jun 2014 19:42:01 -0400 Original-Received: from world.peace.net ([96.39.62.75]:59723 ident=hope5) by debbugs.gnu.org with esmtp (Exim 4.80) (envelope-from ) id 1WrFO3-0007vx-3W for 17485@debbugs.gnu.org; Sun, 01 Jun 2014 19:41:59 -0400 Original-Received: from 209-6-91-212.c3-0.smr-ubr1.sbo-smr.ma.cable.rcn.com ([209.6.91.212] helo=yeeloong.lan) by world.peace.net with esmtpsa (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.72) (envelope-from ) id 1WrFNt-0003Rj-TX; Sun, 01 Jun 2014 19:41:50 -0400 In-Reply-To: <87y4y6t0or.fsf@fencepost.gnu.org> (David Kastrup's message of "Tue, 13 May 2014 12:47:32 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.3 (gnu/linux) X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.15 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 140.186.70.43 X-BeenThere: bug-guile@gnu.org List-Id: "Bug reports for GUILE, GNU's Ubiquitous Extension Language" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Original-Sender: bug-guile-bounces+guile-bugs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.bugs:7472 Archived-At: David Kastrup writes: > The following code results in an error: > > (use-modules (srfi srfi-1)) > (reduce-right + 0 (make-list 10000 1)) [...] > srfi/srfi-1.scm:379:31: In procedure recur: > srfi/srfi-1.scm:379:31: Throw to key `vm-error' with args `(vm-run "VM: Stack overflow" ())'. Yes, this should be fixed. > It turns out that the call of drop-right is responsible here: > > (define (drop-right lis k) > (let recur ((lag lis) (lead (drop lis k))) > (if (pair? lead) > (cons (car lag) (recur (cdr lag) (cdr lead))) > '()))) Thanks for tracking this down. > For all the cleverness involved here, one has to run through the whole > list anyway. It makes no real sense to do this in this manner. The > motivation may be to have a warm cache when k is small, but the result > is self-defeating because of VM stack buildup. > > (define (drop-right lis k) > (drop lis (- (length lis) k))) > > should be all that is needed. That won't be sufficient. SRFI-1 specifies that 'drop-right' works for dotted lists, i.e. finite non-nil-terminated lists, whereas 'length' accepts only proper lists. It includes these examples: (drop-right '(1 2 3 . d) 2) => (1) (drop-right '(1 2 3 . d) 0) => (1 2 3) See . Would you like to propose another fix? Thanks, Mark