[plt-scheme] PLT object system

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

On Feb 17, 2005, at 8:35 AM, David J. Neu wrote:

> Thanks for the info.
>
> Is there a "constructor"  mechanism, i.e. a procedure that is invoked
> each time each new, instantiate or make-object is invoked?

Do you mean created? Sure all expressions in the class definition are 
evaluated when you create an object. So

Welcome to MzScheme version 299.31, Copyright (c) 2004-2005 PLT Scheme, 
Inc.
 > (require (lib "class.ss"))
 > (define x (class object% (super-new) (printf "hello world~n")))
 > (new x)
hello world
#<struct:object:x>
 > (new x)
hello world
#<struct:object:x>
 > (new x)

and so on. It's like a constructor in Java but it's functional -- 
Matthias






>
> Cheers,
> David
>
> On Wed, Feb 16, 2005 at 06:10:51PM -0500, Matthias Felleisen wrote:
>>
>> On Feb 16, 2005, at 5:30 PM, David J. Neu wrote:
>>
>>>  For list-related administrative tasks:
>>>  http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>>
>>> Hi,
>>>
>>> Is there a way to specify a set of fields that a class must implement
>>> using the PLT object system (i.e. class.ss)?
>>>
>>>> From the documentation: "An interface is a collection of method 
>>>> names
>>> to be implemented ..."., is there a similar thing for a set of field
>>> names?
>>
>> 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.
>>
>> -- Matthias
>>
>> P.S. And today I just wrote a macro that makes such fields public.



Posted on the users mailing list.