[plt-scheme] Changing field values in objects

From: Michael Vanier (mvanier at cs.caltech.edu)
Date: Fri Feb 2 06:27:13 EST 2007

This isn't a nice way of doing it, but this works:

<your code, then ...>

(define set-value! (class-field-mutator test% value))
(set-value! t 20)

The nice way, I presume would be to define a public accessor method.

I got this from the class.ss documentation in the libraries manual.  Given my 
very casual perusal, I will say that it looks like it doesn't serve well as a 
tutorial.

Mike

Robert Matovinovic wrote:
> Hi,
> I'm nearly desparate, since I'm trying to do a simple thing: changing the
> value of a field in an object. I read the help desk thoroughly and tried a
> lot, but couldn't find a solution, which to most of you must be obvious. So
> here is a bit of sample code. I would appreciate very much if someone can
> just add the lines to change the value of the value field:
> 
> (define test%
>   (class object%
>     (init-field (value 0))
>     (super-new)
>     )
>   )
> (define t (new test% (value 10)))
> (get-field value t)
> 
> BTW, is there any tutorial to familiarize oneself easily with the object
> system of plt scheme?
> 
> Thanks in advance
> Robert
> 
> _________________________________________
> Robert Matovinovic
> 2 Fenella Drive, Monavale
> Harare
> Zimbabwe
>  
> Tel:    +263 (0)4 339 879
> Cell:   +263 (0)91 43 66 47
> email: robert.matovinovic at web.de
> 
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme


Posted on the users mailing list.