[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Simplified slot access in goops
From: |
Clinton Ebadi |
Subject: |
Re: Simplified slot access in goops |
Date: |
Tue, 02 Dec 2008 15:33:43 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/23.0.60 (gnu/linux) |
"Panicz Maciej Godek" <address@hidden> 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