[plt-scheme] Setter an class inner function call

From: Dave Gurnell (d.j.gurnell at gmail.com)
Date: Wed Mar 10 06:43:25 EST 2010

On 10 Mar 2010, at 11:24, Laurent wrote:

> Searching for my way through macros (and seeing some shiny lights ahead), I wanted to make a getter/setter helper for class fields. [...]

Hi Laurent,

I don't have a specific answer to your question, I'm afraid, but I got something like this to work in the past by expanding the entire "class" form and folding over the statements within.

    http://svn.untyped.com/smoke/branches/bridge/src/class/syntax.ss
    http://svn.untyped.com/smoke/branches/bridge/src/class/syntax-internal.ss

The code is part of a larger Web UI library... it's pretty self-contained but there's some stuff in there that's extraneous to your needs (forms to do with web cells, IDs for HTML elements, #:child keywords, #:callback keywords, and so on). If you cut all the chaff out the code would be very short indeed.

Here's an example:

    (class/cells superclass% ()

      (field my-field initial-value
        #:accessor #:mutator)

      ; generate an accessor and mutator with custom names:
      (field my-other-field initial-value
        #:accessor custom-method-name
        #:mutator other-custom-method-name!))

There are more examples in the tests in SVN:

    http://svn.untyped.com/smoke/branches/bridge/src/class/syntax-test.ss

Cheers,

-- Dave



Posted on the users mailing list.