[plt-scheme] Re: Cloning objects?

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Dec 11 10:17:32 EST 2009

I don't have any better ideas for you on cloning objects, but I can
answer the macro question:

At Wed, 9 Dec 2009 11:38:48 +0100, Laurent wrote:
> On Tue, Dec 8, 2009 at 17:32, Laurent <laurent.orseau at gmail.com> wrote:
> >
> > And, BTW, despite the use of `define-syntax-rule', when omitting the
> > `source' argument in the `init-field-clone' definition,
> > the form still works but becomes non-hygienic! Now I have to completely
> > rewire my brain again...
> >
> >
> More exactly:
> `source' can be omitted from the arguments:
> (define-syntax-rule (init-field-clone [var val] ...)
> >   (begin
> >     (init [source #f])
> >     (init-field [var (if source (get-field var source) val)] ...)))
> >
> it seems that `source' is inaccessible, but then it cannot be used as a
> field anymore:
> > (define c1%
> >   (class object%
> >     (init-field-clone [source "z"])
> >     (super-new)
> >     ))
> > error: class: duplicate declared external init name in: source
> >
> how can this be if the macro is hygienic?
> Well, of course, if it were completely internalized, I could not instantiate
> c1% with `new'...
> Does that means that it is `init' or `init-field' that are non-hygienic?

Each initialization argument, field, and method has two names: an
internal name and an external name. The internal name is an identifier,
so it is subject to the usual scoping and hygiene rules. An external
name, however, is merely a symbol.

For example, when you write

 (send o m 1 2 3)

then the method name `m' doesn't have to be bound in the environment of
the `send' form. The symbol 'm is used as the external name of the

Note that the error message above is specifically about the external

The `define-local-member-name' form creates a scoped binding to be used
as an external name. That's not quite the same thing as having external
names be identifiers, but it provides similar functionality.

Posted on the users mailing list.