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 16:27:50 +0200 Message-ID: <87aa2jk6ft.fsf@gnu.org> References: <871unxhi74.fsf@gnu.org> <87ty0s91l8.fsf@pobox.com> <87bon0boyg.fsf@gnu.org> <87obqzlxmd.fsf@gnu.org> <87d37fbrh1.fsf@netris.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 1334068096 7307 80.91.229.3 (10 Apr 2012 14:28:16 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 10 Apr 2012 14:28:16 +0000 (UTC) Cc: guile-devel@gnu.org To: Mark H Weaver Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Tue Apr 10 16:28:15 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 1SHc3K-0006Oq-AA for guile-devel@m.gmane.org; Tue, 10 Apr 2012 16:28:14 +0200 Original-Received: from localhost ([::1]:59358 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHc3J-0007kl-MU for guile-devel@m.gmane.org; Tue, 10 Apr 2012 10:28:13 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53819) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHc3B-0007PV-6V for guile-devel@gnu.org; Tue, 10 Apr 2012 10:28:11 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SHc31-0002Tn-6E for guile-devel@gnu.org; Tue, 10 Apr 2012 10:28:04 -0400 Original-Received: from xanadu.aquilenet.fr ([88.191.123.111]:60619) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHc30-0002TX-TW for guile-devel@gnu.org; Tue, 10 Apr 2012 10:27:55 -0400 Original-Received: from localhost (xanadu.aquilenet.fr [127.0.0.1]) by xanadu.aquilenet.fr (Postfix) with ESMTP id 9B442765A; Tue, 10 Apr 2012 16:27:51 +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 DDO147Z0jPak; Tue, 10 Apr 2012 16:27:51 +0200 (CEST) Original-Received: from pluto (unknown [193.50.110.167]) by xanadu.aquilenet.fr (Postfix) with ESMTPSA id 270107659; Tue, 10 Apr 2012 16:27:51 +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: <87d37fbrh1.fsf@netris.org> (Mark H. Weaver's message of "Tue, 10 Apr 2012 10:18: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:14246 Archived-At: Hello Mark, Mark H Weaver skribis: > ludo@gnu.org (Ludovic Court=C3=A8s) writes: >> Noah Lavine skribis: >> >>> 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 th= e underlying record type, etc. > > I don't understand why such knowledge is needed, or why this is > difficult. We have procedural macros. Simply sort the field-name-paths > lexicographically, split the sorted paths into groups with the same car, > and recurse. Am I missing something? Yes: nothing forces you to prefix names with =E2=80=98address-=E2=80=99 her= e. >> 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 ca= n do this >> because it turns out that our SRFI-9 records are now =E2=80=9CGuile reco= rds=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. > > The associated runtime cost of searching for fields within the RTDs will > make functional records too slow for many purposes. To my mind, this is > absolutely unacceptable for a data type as fundamental as records. We > need to make functional record update as fast as we possibly can. Agreed. This is why the patch I posted take a purely syntactical approach. Though we must keep in mind that calling these setters involves a =E2=80=98make-struct=E2=80=99 call, which is already expensive. Does anyon= e have figures on the relative cost of (say) a function call compared to a small heap allocation? > Let's not make such a basic data structure slow out of laziness. If you > don't want to implement this, I'd be glad to. Implement what? The proposed =E2=80=98set-fields=E2=80=99? Thanks, Ludo=E2=80=99.