From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: ludo@gnu.org (Ludovic =?iso-8859-1?Q?Court=E8s?=) Newsgroups: gmane.lisp.guile.devel Subject: Re: Functional record =?utf-8?B?4oCcc2V0dGVyc+KAnQ==?= Date: Tue, 10 Apr 2012 11:55:22 +0200 Message-ID: <87obqzlxmd.fsf@gnu.org> References: <871unxhi74.fsf@gnu.org> <87ty0s91l8.fsf@pobox.com> <87bon0boyg.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1334051740 5784 80.91.229.3 (10 Apr 2012 09:55:40 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 10 Apr 2012 09:55:40 +0000 (UTC) Cc: guile-devel@gnu.org To: Noah Lavine Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Apr 10 11:55:40 2012 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 1SHXnX-0002GM-Lr for guile-devel@m.gmane.org; Tue, 10 Apr 2012 11:55:39 +0200 Original-Received: from localhost ([::1]:50161 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHXnX-0004Rs-4n for guile-devel@m.gmane.org; Tue, 10 Apr 2012 05:55:39 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:42163) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHXnQ-0004Qr-Vl for guile-devel@gnu.org; Tue, 10 Apr 2012 05:55:37 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SHXnK-00006K-KU for guile-devel@gnu.org; Tue, 10 Apr 2012 05:55:32 -0400 Original-Received: from xanadu.aquilenet.fr ([88.191.123.111]:52444) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHXnK-00006G-E0 for guile-devel@gnu.org; Tue, 10 Apr 2012 05:55:26 -0400 Original-Received: from localhost (xanadu.aquilenet.fr [127.0.0.1]) by xanadu.aquilenet.fr (Postfix) with ESMTP id A624E76E2; Tue, 10 Apr 2012 11:55:23 +0200 (CEST) Original-Received: from xanadu.aquilenet.fr ([127.0.0.1]) by localhost (xanadu.aquilenet.fr [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 0b47Z8laWaqS; Tue, 10 Apr 2012 11:55:23 +0200 (CEST) Original-Received: from pluto (unknown [193.50.110.167]) by xanadu.aquilenet.fr (Postfix) with ESMTPSA id 3DC7676E1; Tue, 10 Apr 2012 11:55:23 +0200 (CEST) X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 22 Germinal an 220 de la =?iso-8859-1?Q?R=E9volution?= 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: (Noah Lavine's message of "Mon, 9 Apr 2012 21:19:18 -0400") User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.93 (gnu/linux) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 88.191.123.111 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:14244 Archived-At: Hi! Noah Lavine skribis: > Since updating a field requires creating a new record object (I > think), it seems useful to have an interface to update many fields at > once, to avoid creating many temporary objects. Yes, others mentioned it on IRC, though I=E2=80=99m wondering how common th= is is in practice. > In the spirit of brainstorming, I have two ideas to offer. First, > here's an extended version of your example: > > (let* ((p1 (set-field (person-address address-city) p "D=C3=BCsseldorf")) > (p2 (set-field (age) p1 32)))) > > 1. Alternate a lists of field names and values. The example becomes > (set-field p (person-address address-city) "D=C3=BCsseldorf" (age) 32) I prefer this one. Perhaps it could be called =E2=80=98set-fields=E2=80=99= , even. However, generating the most optimal code may prove to be complicated. For instance, you=E2=80=99d want: (set-fields p (person-address address-city) "D=C3=BCsseldorf" (person-address address-street) "Bar") to expand to: (set-person-address p (let ((a (person-address p))) (set-fields a (address-city) "D=C3=BCsseldorf" (address-street) "Bar"))) But that would require knowledge of the relationship between =E2=80=98address-city=E2=80=99, =E2=80=98address-street=E2=80=99, and the u= nderlying record type, etc. Instead, I think I=E2=80=99ll add =E2=80=98record-copy=E2=80=99, similar to= Racket=E2=80=99s =E2=80=98struct-copy=E2=80=99 [0], as Ian Price suggested on IRC. We can d= o this because it turns out that our SRFI-9 records are now =E2=80=9CGuile records= =E2=80=9D, and thus they have a run-time type descriptor that maps field names to their indices. The drawback compared to generated setters as above is that field lookup happens at run-time, which degrades performance and delays any error report to execution time. Thanks, Ludo=E2=80=99. [0] http://docs.racket-lang.org/reference/struct-copy.html