[plt-scheme] Field names in the class system

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Sat Aug 1 10:18:55 EDT 2009

Use init-field.

On Aug 1, 2009, at 9:59 AM, Todd O'Bryan wrote:

> 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
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme



Posted on the users mailing list.