[plt-scheme] Field names in the class system

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Sat Aug 1 09:59:03 EDT 2009

How do I get the names I use when passing in values with new to match
the internal field names?

In other words, I'd like to be able to do

(new foo% [name "blah"])

and then assign the field name the value "blah" inside the class.

My first attempt was:

(define foo%
  (class object%
    (init name)

    (super-new)

    (define name name)))   ; doesn't work because name is already defined

I tried using the maybe-renamed construct, but the name is backwards
from what I expected:

(define foo%
  (class object%
    (init (field-name name))
    ...)

means that I have to do (new foo% [field-name "blah"]), rather than
[name "blah"].

I'm sure I'm just missing something obvious...

Todd


Posted on the users mailing list.