[plt-scheme] A macro for declaring class properties, a question
At Thu, 18 Oct 2007 19:20:49 +0200, Jens Axel Soegaard wrote:
> Grant Rettke skrev:
> > On 10/18/07, Matthias Felleisen <matthias at ccs.neu.edu> wrote:
> >> No. See macro-stepper.
> >
> > I got an error "class*: duplicate declared external field name in:
> > super-secret-field-name"
>
> That's due to the following code from class-internal.ss, which
> uses (syntax-e id) to convert the identifiers to symbols, thus
> deleting any marks.
>
> In short, normally it would have worked, but not in this case.
> It only if the you expand to plays fair.
To be clear, this is not a bug in the `class' macro. A `field'
declaration creates a public, externally accessible field, and external
names are symbols.
Use `define' to make a private field. That is, change the macro to
(define-syntax property
(syntax-rules ()
[(_ name)
(begin
(define super-secret-field-name null) ;; <<<<
(define/public name
(case-lambda
[() super-secret-field-name]
[(value) (set! super-secret-field-name value)])))]))
and now it work work as expected, because it's not adding a publicly
accessible `super-secret-field-name' field.
Matthew