AW: [plt-scheme] Changing field values in objects

From: Robert Matovinovic (robert.matovinovic at
Date: Fri Feb 2 08:01:54 EST 2007

Thank you Michael,
You're right, it works but somehow it looks not very elegant. I experimented
with it and came up with the following define-syntax:

(define-syntax set-field!
  (syntax-rules ()
    ((set-field! f c obj val) ((class-field-mutator c f) obj val))

Now I can write (set-field! value test% t 20)

This is a bit more general, because I now can access every field. What is
still a little bit weird is that I need the class explicitly, since
(object-info t) -> #f #t. The #f means that it doesn't know the class. How
do I get the class of an object, if not via that way?


-----Ursprüngliche Nachricht-----
Von: plt-scheme-bounces at
[mailto:plt-scheme-bounces at] Im Auftrag von Michael Vanier
Gesendet: Friday, February 02, 2007 12:27
An: Robert Matovinovic
Cc: plt-scheme at
Betreff: Re: [plt-scheme] Changing field values in objects

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 documentation in the libraries manual.  Given
very casual perusal, I will say that it looks like it doesn't serve well as


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
> _________________________________________________
>   For list-related administrative tasks:
  For list-related administrative tasks:

Posted on the users mailing list.