[plt-scheme] PLT object system
On Feb 18, 2005, at 10:04 PM, Doug Orleans wrote:
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Matthias Felleisen writes:
>> On Feb 17, 2005, at 8:35 AM, David J. Neu wrote:
>>> 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
>
> What's functional about it?
(define foo
(class object%
(init-field x y z)
(field [w (+ x y z)])
(super-new)))
No set! needed to set up an object. -- Matthias