[plt-scheme] class fields and accessors

From: Mike T. Machenry (dskippy at ccs.neu.edu)
Date: Fri Sep 13 13:32:14 EDT 2002

  In the documentation for many of the mred classes, they have initilization
arguments and access/mutate'ers of the same name. For example
horizontal-panel% has an initialization argument for spacing and has a
method spacing which (based on its arguments) either accesses or mutates
the field initilized by spacing. When I attempt a simple class to do the
same:

(require (lib "class.ss"))
(define example%
  (class object%
    (init-field spacing)
    (define/public spacing
      (case-lambda
        [(new-spacing) (set! spacing new-spacing)]
        [() spacing]))
    (super-instantiate ())))

I get the error "class*/names: duplicate declared identifier in: spacing"
Is there a proper way to work around this? I was told some time ago that
I can create a class that contains the fields and then derive a class that
inherits those fields and add accessors. I couldn't get this to work as
inherit-field causes the same problem. How do the mred classes do this?

-mike



Posted on the users mailing list.