From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Panicz Maciej Godek Newsgroups: gmane.lisp.guile.user Subject: Re: Simplified slot access in goops Date: Sun, 29 Aug 2010 02:22:53 +0200 Message-ID: References: NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1283041387 4576 80.91.229.12 (29 Aug 2010 00:23:07 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 29 Aug 2010 00:23:07 +0000 (UTC) Cc: guile-user@gnu.org, Maciek Godek To: Andy Wingo Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Aug 29 02:23:05 2010 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.69) (envelope-from ) id 1OpVfs-0005EO-RQ for guile-user@m.gmane.org; Sun, 29 Aug 2010 02:23:05 +0200 Original-Received: from localhost ([127.0.0.1]:58047 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OpVfr-00039Z-1Y for guile-user@m.gmane.org; Sat, 28 Aug 2010 20:23:03 -0400 Original-Received: from [140.186.70.92] (port=41142 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1OpVfk-00038J-2a for guile-user@gnu.org; Sat, 28 Aug 2010 20:22:57 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.69) (envelope-from ) id 1OpVfi-0003P7-Px for guile-user@gnu.org; Sat, 28 Aug 2010 20:22:55 -0400 Original-Received: from mail-ww0-f49.google.com ([74.125.82.49]:58457) by eggs.gnu.org with esmtp (Exim 4.69) (envelope-from ) id 1OpVfi-0003Ob-Lq for guile-user@gnu.org; Sat, 28 Aug 2010 20:22:54 -0400 Original-Received: by wwb24 with SMTP id 24so1354060wwb.30 for ; Sat, 28 Aug 2010 17:22:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:received:in-reply-to :references:date:message-id:subject:from:to:cc:content-type :content-transfer-encoding; bh=cwjcBJg5vk86f+KI/xEdRy7FzxkK26Oe067stleMbpU=; b=Ia6XBLcXY9mWrSn4UxSh57bT/8a95i2mXODn2J+/uwIMeqZ74dYw27FoxAh76x01fW pRZlNenj5/dOx6gNt/Z85W2VgGSgYM8zU8eTjGYY51votpHgqOTlMCjxFDujMhoTpz1c Ov03Y2XzY8LkthSo3hl7pznswMaQQld0f8w0w= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type:content-transfer-encoding; b=GW5xXm/Ubnk+uEIAmo/2fQJzGXDXIZmuYNqRi+SOLMtw2V5JIMJ1jPcZwgXikN5qMo /ArrxkzxI3GWuDCT1/6QCPE2tKLNhh14gYkY13rqAJih3ZGrs3Asvc9yTb1fqBTnp4Ce FM+Cf3Lwsr/TBP7UrZ5PnnT8Ed+LR7kLlT05A= Original-Received: by 10.227.128.18 with SMTP id i18mr2810913wbs.135.1283041373115; Sat, 28 Aug 2010 17:22:53 -0700 (PDT) Original-Received: by 10.216.49.85 with HTTP; Sat, 28 Aug 2010 17:22:53 -0700 (PDT) In-Reply-To: X-detected-operating-system: by eggs.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:8114 Archived-At: 2010/8/28 Andy Wingo : > Hi Maciek, > > I know its been a couple years, but you raised an interesting point that > Guile wasn't really able to handle at that point. Your implementation of > `in' (commonly known as `with-slots', I believe) follows the mail. > > On Thu 27 Nov 2008 12:36, "Maciek Godek" writes: > >> (use-modules (oop goops)) >> (use-syntax (ice-9 syncase)) > > With Guile 2.0 (coming shortly!), there is no more need to use ice-9 > syncase. > >> Now suppose we have an instance of a class: >> (define-class C () >> =A0 a b c) >> (define o (make C)) >> >> Using the "in" macro, we can write: >> (in o >> =A0 (set! a 5) >> =A0 (set! b (1+ a)) >> =A0 (set! c (+ a b)) >> =A0 (+ a b c)) >> =3D> 22 > > The problem with this macro is that `o' can be of any type at all, but > Guile needs to know at least whether a given identifier is a macro or a > local variable or what, at expansion time. > > So for that reason, with-slots usually takes a list of slots, explicitly: > > =A0(with-slots o (a b c) > =A0 =A0(set! a 5) > =A0 =A0(set! b (1+ a)) > =A0 =A0(set! c (+ a b)) > =A0 =A0(+ a b c)) > > It would be possible to pass the class instead, but then the class would > need to be known at compile-time, and you run into a number of issues > there. Anyway, here's that with-slots definition: > > =A0(define-syntax with-slots > =A0 =A0(syntax-rules () > =A0 =A0 =A0((_ obj (slot ...) b b* ...) > =A0 =A0 =A0 (let-syntax > =A0 =A0 =A0 =A0 =A0 ((slot (identifier-syntax > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0(id (slot-ref obj 'slot)) > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0((set! id val) (slot-set! obj 'slo= t val)))) > =A0 =A0 =A0 =A0 =A0 =A0...) > =A0 =A0 =A0 =A0 b b* ...)))) > > Here we use the new settable identifier-syntax. > > Note that slot-ref / slot-set isn't the most efficient way to reference > slots; the best thing is to use accessors, which JIT-compile (sorta) to > struct-ref opcodes, but we don't know that accessors exist for these > slots. You can define a with-accessors macro though, that does assume > accessors are available. > > In fact with more assumptions, it's possible to compile to struct-ref / > struct-set yourself -- see the examples in the "Syntax" chapter of "The > Scheme Programming Language" 4th edition (available online) for an > illuminating take on the issue. It's good to know all that. Indeed, it's been some time and the development of my project has lost some of its robustness, but maybe I would continue my work soon, so this news can turn out to be motivating :) If it comes to the performance issues, I've been wondering, what is the current state of guile-vm? I have a friend who's been developing a variant of a SECD machine in order to research the topics of partial evaluation. You can take a look at his project here: http://drczlang.sourceforge.net/ If you think that it would make sense, I could try to convince him to contribute to guile-vm. (I have no idea how this machine is implemented, but I've been thinking about implementing a SECD atop of i386 assembler; I'm only not sure whether gcc isn't wiser than me when it comes to low-level programming) best regards m