From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Maciek Godek" Newsgroups: gmane.lisp.guile.user Subject: Simplified slot access in goops Date: Thu, 27 Nov 2008 21:36:30 +0100 Message-ID: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Trace: ger.gmane.org 1227818228 22531 80.91.229.12 (27 Nov 2008 20:37:08 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 27 Nov 2008 20:37:08 +0000 (UTC) To: guile-user@gnu.org Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Nov 27 21:38:10 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 1L5nco-00026V-5K for guile-user@m.gmane.org; Thu, 27 Nov 2008 21:38:10 +0100 Original-Received: from localhost ([127.0.0.1]:33431 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5nbe-0002Aa-Fh for guile-user@m.gmane.org; Thu, 27 Nov 2008 15:36:58 -0500 Original-Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1L5nbG-00026P-Pm for guile-user@gnu.org; Thu, 27 Nov 2008 15:36:34 -0500 Original-Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1L5nbF-00024w-3O for guile-user@gnu.org; Thu, 27 Nov 2008 15:36:34 -0500 Original-Received: from [199.232.76.173] (port=43277 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1L5nbE-00024k-Q3 for guile-user@gnu.org; Thu, 27 Nov 2008 15:36:32 -0500 Original-Received: from an-out-0708.google.com ([209.85.132.249]:3943) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1L5nbE-0002hT-Ew for guile-user@gnu.org; Thu, 27 Nov 2008 15:36:32 -0500 Original-Received: by an-out-0708.google.com with SMTP id c38so467268ana.21 for ; Thu, 27 Nov 2008 12:36:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:to :subject:mime-version:content-type:content-transfer-encoding :content-disposition; bh=I2xpj0sx3FmS7FTrOmwOgyXz7j0Z3ttD68Cq7lhMLx8=; b=pjVxQzpuqOu+mM9Xsz9dnJfDa8f84yq/FefJf406YZnO6oIz5ubwi9I/8j5jKQ1cnA VcdD7Cy/LOO8zpdBVEP2j4GDi/3ZAmezF6GECamg0fj7aO3vN6pZDHAVP0oLxGdQHVXT b8BJxOqBFMEJio5ZTASLuWF2zUUEPrGIl2GuM= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:to:subject:mime-version:content-type :content-transfer-encoding:content-disposition; b=OSvA+Rr8pVp9pWc+gSrNYydQLKLSOke7ywVLnlJxxi15drFp2XYJRkKdMkCzlrQHpX JKARCoZ2jrGlCKpJssG8/RvSoDibocQuFmz1jY/aXL9mo7JR0e58iRcqhdsDl2IqG5+j mH2rDn8n+AXg82z8/q6suY8szF4ajCQZ0lcu0= Original-Received: by 10.100.133.2 with SMTP id g2mr3693741and.134.1227818190142; Thu, 27 Nov 2008 12:36:30 -0800 (PST) Original-Received: by 10.100.210.5 with HTTP; Thu, 27 Nov 2008 12:36:30 -0800 (PST) Content-Disposition: inline X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 2) 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:6981 Archived-At: Hi, Below is a simple set of functions and macros to make the access to goops object properties easier: (use-modules (oop goops)) (use-syntax (ice-9 syncase)) (define-syntax let-alias (syntax-rules () ((_ ((id alias) ...) body ...) (let-syntax ((helper (syntax-rules () ((_ id ...) (begin body ...))))) (helper alias ...))))) (define slot (make-procedure-with-setter slot-ref slot-set!)) (define-syntax in (syntax-rules () ((_ object expr ...) (primitive-eval (list 'let-alias (map (lambda(s)(list(car s)(list 'slot object (list 'quote (car s))))) (class-slots (class-of object))) (quote expr) ...))))) Now suppose we have an instance of a class: (define-class C () a b c) (define o (make C)) Using the "in" macro, we can write: (in o (set! a 5) (set! b (1+ a)) (set! c (+ a b)) (+ a b c)) => 22 which is more convenient than: (slot-set! o 'a 5) (slot-set! o 'b (1+ (slot-ref o 'a)) (slot-set! o 'c (+ (slot-ref o 'a) (slot-ref o 'b))) (+ (slot-ref o 'a) (slot-ref o 'b) (slot-ref o 'c)) Perhaps the possible inconvenience is that all variable names that happen to be the slot names of a given class are shadowed. In the long run it may also cause significant performance problems (or that's what I think), especially when dealing with objects with a hell lotta slots. I wonder if it would be possible to make it optimizable for the JIT compiler somehow (and to make the "in" syntax official part of GOOPS) Sincerely, M.