From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Clinton Ebadi Newsgroups: gmane.lisp.guile.user Subject: Re: Simplified slot access in goops Date: Tue, 02 Dec 2008 15:33:43 -0500 Message-ID: <87hc5mxqoo.fsf@unknownlamer.org> References: <49dd78620812011425k2720df81tbf3820b429ba7ba@mail.gmail.com> <87ljuyylav.fsf@unknownlamer.org> <1eb53f5d0812021130u5b41964pa20464a35ce67715@mail.gmail.com> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1228250054 11984 80.91.229.12 (2 Dec 2008 20:34:14 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Tue, 2 Dec 2008 20:34:14 +0000 (UTC) Cc: guile-user@gnu.org, Neil Jerram To: "Panicz Maciej Godek" Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Dec 02 21:35:17 2008 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1L7bxl-0006iu-6O for guile-user@m.gmane.org; Tue, 02 Dec 2008 21:35:17 +0100 Original-Received: from localhost ([127.0.0.1]:49809 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L7bwY-0001JU-UR for guile-user@m.gmane.org; Tue, 02 Dec 2008 15:34:02 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L7bwU-0001HK-4k for guile-user@gnu.org; Tue, 02 Dec 2008 15:33:58 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L7bwS-0001EU-Lj for guile-user@gnu.org; Tue, 02 Dec 2008 15:33:57 -0500 Original-Received: from [199.232.76.173] (port=53047 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L7bwS-0001EH-GX for guile-user@gnu.org; Tue, 02 Dec 2008 15:33:56 -0500 Original-Received: from deleuze.hcoop.net ([69.90.123.67]:45245) by monty-python.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.60) (envelope-from ) id 1L7bwS-0007YM-6P for guile-user@gnu.org; Tue, 02 Dec 2008 15:33:56 -0500 Original-Received: from cpe-024-211-230-216.nc.res.rr.com ([24.211.230.216] helo=rvannith) by deleuze.hcoop.net with esmtpsa (TLS-1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.63) (envelope-from ) id 1L7bwO-0003ie-95; Tue, 02 Dec 2008 15:33:52 -0500 In-Reply-To: <1eb53f5d0812021130u5b41964pa20464a35ce67715@mail.gmail.com> (Panicz Maciej Godek's message of "Tue, 2 Dec 2008 20:30:11 +0100") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 1) X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:6990 Archived-At: "Panicz Maciej Godek" writes: >> with-slots uses symbol-macrolet[0] to bind each of the variable names to >> symbol macros within its body. I don't know of anything in Guile that is >> equivalent. > > R5RS pattern language allows to create syntactic aliases for practically > any form. Some time ago I've found the following `let-alias' macro that does > just this: Ah, I suspected that syntax-case supported something like this. > (use-syntax (ice-9 syncase)) > > (define-syntax let-alias > (syntax-rules () > ((_ ((id alias) ...) body ...) > (let-syntax ((helper (syntax-rules () > ((_ id ...) (begin body ...))))) > (helper alias ...))))) > > ;; And here's the code for the aforementioned with-object-slots and let-slots: > > (use-modules (oop goops)) > (define slot-ref (make-procedure-with-setter slot-ref slot-set!)) > > (define-syntax with-object-slots (syntax-rules () > ((_ (object (alias1 slot1) ...) expr1 ...) > (let-alias ((alias1 (slot-ref > object (quote slot1))) ...) > expr1 ...)) > ((_ (object prop1 ...) expr1 ...) > (let-alias ((prop1 (slot-ref object > (quote prop1))) ...) > expr1 ...)))) > > (define-syntax let-slots (syntax-rules () > ((_ () expr1 ...) > (begin expr1 ...)) > ((_ (binding1 binding2 ...) expr1 ...) > (with-object-slots binding1 > (let-slots (binding2 ...) > expr1 ...))))) -- Ethan: i'm working on myself Ethan: the self is the most important thing Ethan: i learned this from a packet of tea