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

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Thu Feb 17 10:43:02 EST 2005

At Thu, 17 Feb 2005 09:23:38 -0600, ian barland (will wake for food) wrote:
> 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?

Methods are per-class, so they can only access variables that are
either bound outside the `class' expression or available via slots.

But `init' arguments act like constructor arguments. You don't
necessarily want to allocate a slot in each object for each constructor

If the `class' macro could detect which `init' arguments are referenced
inside method bodies, then it could automatically move them into slots.
But detecting uses of `init' arguments would require fully expanding
the sub-expressions of a `class' expression before expanding the
`class' form itself, and that creates order-of-expansion problems.


Posted on the users mailing list.