From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?utf-8?Q?Court=C3=A8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: for-each et al Date: Tue, 04 Mar 2014 23:35:44 +0100 Message-ID: <87ob1l383j.fsf@gnu.org> References: <87txbgr3wx.fsf@pobox.com> <87r46ks33b.fsf@gnu.org> <87wqg9ogf2.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: ger.gmane.org 1393972560 3211 80.91.229.3 (4 Mar 2014 22:36:00 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 4 Mar 2014 22:36:00 +0000 (UTC) Cc: guile-devel@gnu.org To: Andy Wingo Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Mar 04 23:36:05 2014 Return-path: Envelope-to: guile-devel@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 1WKxwP-0005Cd-Fi for guile-devel@m.gmane.org; Tue, 04 Mar 2014 23:36:01 +0100 Original-Received: from localhost ([::1]:48937 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKxwO-0006fC-Kl for guile-devel@m.gmane.org; Tue, 04 Mar 2014 17:36:00 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56269) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKxwG-0006eP-0w for guile-devel@gnu.org; Tue, 04 Mar 2014 17:35:56 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WKxwB-0003aY-B8 for guile-devel@gnu.org; Tue, 04 Mar 2014 17:35:51 -0500 Original-Received: from hera.aquilenet.fr ([2a01:474::1]:43865) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WKxwA-0003Zw-T9 for guile-devel@gnu.org; Tue, 04 Mar 2014 17:35:47 -0500 Original-Received: from localhost (localhost [127.0.0.1]) by hera.aquilenet.fr (Postfix) with ESMTP id 8B71B431; Tue, 4 Mar 2014 23:35:45 +0100 (CET) Original-Received: from hera.aquilenet.fr ([127.0.0.1]) by localhost (hera.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id TaUhOlbqeY0m; Tue, 4 Mar 2014 23:35:45 +0100 (CET) Original-Received: from pluto (reverse-83.fdn.fr [80.67.176.83]) by hera.aquilenet.fr (Postfix) with ESMTPSA id 26B0D259; Tue, 4 Mar 2014 23:35:45 +0100 (CET) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 14 =?utf-8?Q?Vent=C3=B4se?= an 222 de la =?utf-8?Q?R?= =?utf-8?Q?=C3=A9volution?= X-PGP-Key-ID: 0xEA52ECF4 X-PGP-Key: http://www.fdn.fr/~lcourtes/ludovic.asc X-PGP-Fingerprint: 83C4 F8E5 10A3 3B4C 5BEA D15D 77DD 95E2 EA52 ECF4 X-OS: x86_64-unknown-linux-gnu In-Reply-To: <87wqg9ogf2.fsf@pobox.com> (Andy Wingo's message of "Tue, 04 Mar 2014 21:30:25 +0100") User-Agent: Gnus/5.130007 (Ma Gnus v0.7) Emacs/24.3 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a01:474::1 X-BeenThere: guile-devel@gnu.org X-Mailman-Version: 2.1.14 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 Original-Sender: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.devel:16946 Archived-At: Andy Wingo skribis: > On Sun 02 Mar 2014 22:27, ludo@gnu.org (Ludovic Court=C3=A8s) writes: [...] >> I think an important difference you didn=E2=80=99t mention is that =E2= =80=98list?=E2=80=99 does >> its list traversal in C. > > That's true. Let's call the above version for-each*. Then we have > for-each**, which is the same except it calls list*, which is: > > (define (list*? l) > (let lp ((hare l) (tortoise l)) > (or (null? hare) > (and (pair? hare) > (let ((hare (cdr hare))) > (or (null? hare) > (and (pair? hare) > (not (eq? tortoise hare)) > (lp (cdr hare) (cdr tortoise))))))))) > > Then we have: > > scheme@(guile-user)> (define l (iota 100000000)) > scheme@(guile-user)> ,time (for-each** (lambda (x) x) l) > ;; 3.228201s real time, 3.223919s run time. 0.000000s spent in GC. > scheme@(guile-user)> ,time (for-each* (lambda (x) x) l) > ;; 2.356612s real time, 2.353496s run time. 0.000000s spent in GC. > scheme@(guile-user)> ,time (for-each (lambda (x) x) l) > ;; 3.142366s real time, 3.126806s run time. 0.000000s spent in GC. > > So the overhead of traversing the list twice is negligible in the worst > case, and probably we still gain once the compiler gets better. Yes. >>> (lambda (f l) >>> (unless (list? l) >>> (scm-error 'wrong-type-arg "for-each" "Not a list: ~S" (list l) #= f)) >>> (let for-each1 ((l l)) >>> (unless (null? l) >>> (f (car l)) >>> (for-each1 (cdr l))))) > >> I=E2=80=99m OK with this implementation. I=E2=80=99ve never found mysel= f iterating over >> a list and modifying it concurrently. > > Yeah it's something that no one in their right mind does. But still we > should have some kind of statement about what we guarantee -- currently > the code is resilient to concurrent mutation, and we'd be relaxing that. Right. R5 and R6 don=E2=80=99t say anything about that, but yes, we can ad= d a statement in the manual and NEWS to that effect. I think the for-each change would be for 2.2, right? >> I=E2=80=99m all in favor of immutable pairs. However, I expect that a l= ot of >> code out there relies on it. >> >> Moving set-car! and set-cdr! to a different module like in R6 may be a >> good first (or second) step. > > Brainstorming possibilities: > > * Deprecate set-car!/set-cdr! (replacement would be mutable cells in > the car/cdr; currently called variables, but could be called boxes) SRFI-111 boxes. We should check a few existing packages and usage patterns before. For instance, I suspect SCM_SETCAR/SCM_SETCDR are actually more widespread than their Scheme counterparts, and probably much harder to avoid. What can we do with them? Another issue: what about elisp? It needs mutable pairs, but we don=E2=80= =99t want to have it use a disjoint type. > * Introducing a #!lang facility, and having programs with #!lang make > immutable pairs Not really fan of the idea. :-) Thanks, Ludo=E2=80=99.