unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Panicz Maciej Godek <godek.maciek@gmail.com>
To: Andy Wingo <wingo@pobox.com>
Cc: guile-user@gnu.org, Maciek Godek <pstrychuj@gmail.com>
Subject: Re: Simplified slot access in goops
Date: Sun, 29 Aug 2010 02:22:53 +0200	[thread overview]
Message-ID: <AANLkTi=R2ezQVcQ4DFtC_-Mq8+DEjmABFvqs0jyTSwPS@mail.gmail.com> (raw)
In-Reply-To: <m38w3q33iv.fsf@unquote.localdomain>

2010/8/28 Andy Wingo <wingo@pobox.com>:
> 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" <pstrychuj@gmail.com> 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 ()
>>   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
>
> 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:
>
>  (with-slots o (a b c)
>    (set! a 5)
>    (set! b (1+ a))
>    (set! c (+ a b))
>    (+ 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:
>
>  (define-syntax with-slots
>    (syntax-rules ()
>      ((_ obj (slot ...) b b* ...)
>       (let-syntax
>           ((slot (identifier-syntax
>                    (id (slot-ref obj 'slot))
>                    ((set! id val) (slot-set! obj 'slot val))))
>            ...)
>         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



  reply	other threads:[~2010-08-29  0:22 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-11-27 20:36 Simplified slot access in goops Maciek Godek
2008-11-28 18:41 ` Panicz Maciej Godek
2008-12-01 22:25 ` Neil Jerram
2008-12-02  9:32   ` Clinton Ebadi
2008-12-02 19:30     ` Panicz Maciej Godek
2008-12-02 20:33       ` Clinton Ebadi
2010-08-28 20:07 ` Andy Wingo
2010-08-29  0:22   ` Panicz Maciej Godek [this message]
2010-08-29  0:56     ` Andy Wingo

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='AANLkTi=R2ezQVcQ4DFtC_-Mq8+DEjmABFvqs0jyTSwPS@mail.gmail.com' \
    --to=godek.maciek@gmail.com \
    --cc=guile-user@gnu.org \
    --cc=pstrychuj@gmail.com \
    --cc=wingo@pobox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).