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: Mon, 09 Apr 2012 23:00:23 +0200 Message-ID: <87bon0boyg.fsf@gnu.org> References: <871unxhi74.fsf@gnu.org> <87ty0s91l8.fsf@pobox.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Trace: dough.gmane.org 1334005252 30069 80.91.229.3 (9 Apr 2012 21:00:52 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 9 Apr 2012 21:00:52 +0000 (UTC) To: guile-devel@gnu.org Original-X-From: guile-devel-bounces+guile-devel=m.gmane.org@gnu.org Mon Apr 09 23:00:51 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 1SHLhf-0003sa-VX for guile-devel@m.gmane.org; Mon, 09 Apr 2012 23:00:48 +0200 Original-Received: from localhost ([::1]:37268 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHLhf-0000lG-F1 for guile-devel@m.gmane.org; Mon, 09 Apr 2012 17:00:47 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:34492) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHLhc-0000ku-5u for guile-devel@gnu.org; Mon, 09 Apr 2012 17:00:45 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1SHLha-0006Ar-9L for guile-devel@gnu.org; Mon, 09 Apr 2012 17:00:43 -0400 Original-Received: from plane.gmane.org ([80.91.229.3]:36360) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1SHLha-0006Ad-2F for guile-devel@gnu.org; Mon, 09 Apr 2012 17:00:42 -0400 Original-Received: from list by plane.gmane.org with local (Exim 4.69) (envelope-from ) id 1SHLhU-0003oZ-C3 for guile-devel@gnu.org; Mon, 09 Apr 2012 23:00:36 +0200 Original-Received: from reverse-83.fdn.fr ([80.67.176.83]) by main.gmane.org with esmtp (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 Apr 2012 23:00:36 +0200 Original-Received: from ludo by reverse-83.fdn.fr with local (Gmexim 0.1 (Debian)) id 1AlnuQ-0007hv-00 for ; Mon, 09 Apr 2012 23:00:36 +0200 X-Injected-Via-Gmane: http://gmane.org/ Original-Lines: 77 Original-X-Complaints-To: usenet@dough.gmane.org X-Gmane-NNTP-Posting-Host: reverse-83.fdn.fr X-URL: http://www.fdn.fr/~lcourtes/ X-Revolutionary-Date: 21 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 User-Agent: Gnus/5.110018 (No Gnus v0.18) Emacs/24.0.93 (gnu/linux) Cancel-Lock: sha1:Eanxk6HnULa5xS49a4ABPEXBN+0= X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 80.91.229.3 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:14239 Archived-At: Hi Andy! Thanks for your quick feedback! Andy Wingo skribis: >> + (define-inlinable (modifier s val) >> + (if (eq? (struct-vtable s) #,type-name) >> + (struct-set! s index val) >> + (throw 'wrong-type-arg 'modifier >> + "Wrong type argument: ~S" (list s) >> + (list s))))))))) > > Any better abstraction here? It can be a big win to just pass the > vtable to some function, because you avoid emitting code and constants. > (It will be nice to start to elide some of these checks in the > optimizer...) > > E.g. (throw-bad-struct s 'modifier). Indeed, will do. > Same for the getter. ("Getter" and "setter" are better names IMO, > because of other uses of the name "accessor" in Guile.) “Modifier” was already in, but I should unify it, yes. >> (syntax-case x () >> - ((_ type-name constructor-spec predicate-name field-spec ...) >> + ((_ immutable? type-name constructor-spec predicate-name >> + field-spec ...) > > I realize this is an internal macro, but it would be nice to support > keywords (#:immutable), possibly without arguments... Not sure I understand. Macros can have keyword arguments? >> +;; Import (srfi srfi-9)'s private module, so we can use the private >> +;; `%define-record-type' macro. >> +(eval-when (compile eval load) >> + (module-use! (current-module) (resolve-module '(srfi srfi-9)))) > > Why not just use (@@ (srfi srfi-9) %define-record-type) ? Indeed. >> (%define-record-type)[functional-accessors]: Mimic `define-inlinable', >> but add support for (ACCESSOR obj val), when `%reveal-setter' allows >> it. > > This is confusing naming. ‘functional-accessors’ and ‘accessors’ produce code for both getters and setters. I used “accessor” to mean either “getter or setter”, or just “getter”, which is what’s confusing, I think. I’ll improve that. > I find the set-fields interface a bit strange, FWIW. Are you happy with > it, or do you think it could be better? If you think it's really the > thing to do, OK. The goal was to have an interface close to what one would do in imperative programming, that is: person.address.city = "foo"; I think it’s quite successful at it. Now, I’m open for suggestions. I don’t have any idea for a better interface that meets this goal. For instance, having to spell out the getter names may look verbose, but I don’t see how it can be avoided. Any ideas? Thanks, Ludo’.