[plt-scheme] class.ss's init, and non-public fields

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Thu Feb 17 10:28:33 EST 2005

On Feb 17, 2005, at 10:23 AM, ian barland (will wake for food) wrote:

>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>> Is there a way to specify a set of fields that a class must implement
>>> using the PLT object system (i.e. class.ss)?
>> Come to a neighborhood near you real soon, or so they say. But don't
>> hold your breath.
>>> If not how do you do this - define a superclass that contains the
>>> required fields and derive a new class from it?
>> Yes.
> A different question, also about class.ss.  From the docs:
> ]
> ] Only initialization variables declared with init-field can be 
> accessed
> ] from methods; accessing any other initialization variable from a 
> method
> ] is a syntax error.
> ]
> (1a) Why this restriction?
> (1b) Is there a workaround better than
>   ...
>   (init size)
>   (define _init init) ; use _init inside my own methods

That makes a field _init. So why noy

  (init-field size)

>   ...
> (2) class.ss doesn't have abstract classes.  After some thought, I
> realize it's because it's an unnecessary concept?

It's probably unnecessary but you can always fake it. I wrote a 
three-line macro that does the minimum.

> ('Abstract class' just means a class that doesn't fully meet the 
> interface
> you want yet; instead use an interface to describe the type, and
> an ordinary class Abstr% (not meeting the interface) to hold any 
> shared code,
> and then extend Abstr% with classes that *do* meet the interface.)
> (2a) Is there anything subtle which abstract classes provide, and
>      this approach doesn't?

The only thing I can think of is that you can't create an instance of 
an abstract class by accident. There are other ways of avoiding that.

> (2b) Hmm, a short "class.ss for java programmers" might be a useful 
> page
>      for students.  I'll get to this eventually myself, but it won't
>      be 'til the end of the semester at least...

I will teach a grad course on interpreters using our class system next 
semester, so perhaps it's on my plate, too.

-- Matthias

Posted on the users mailing list.