[plt-scheme] A macro for declaring class properties, a question

From: David Einstein (deinst at gmail.com)
Date: Thu Oct 18 09:21:50 EDT 2007

On 10/18/07, Grant Rettke <grettke at acm.org> wrote:
> Hi folks,
> I wanted to start by writing a macro to declare (MzLib) class
> properties. A class property feature looks like:
> (field (field-X null))
> (define/public (X . args)
>     (if (null? args) x
>         (set! field-X (car args))))
> Classes can look like this now:
> (define service-call%
>   (class* object% ()
>     (property customer-name)
>     (property customer-id)
>     (property call-type-code)
>     (property date-of-call-string)
>     (super-new)))
> I'm only learning about macros. That said, if you have a look at the
> macro (at the end), is there anything obviously wrong about it? right
> about it? any comments or advice?
> The next step is that I would like to be able to do this:
> (define service-call%
>   (class* object% ()
>     (property customer-name customer-id call-type-code
> date-of-call-string)
>     (super-new)))
> But I don't understand how to do that. Any ideas?
> For reading I am sticking with TSPL3 and the Help Desk. Anywhere else
> I should look?

Recently, I've spent my weekends pestering Jens on similar topics.  In
response to a similar question he reccomended

"Two articles to start with are:

  Writing hygienic macros in Scheme with syntax-case.
  Kent Dybvig

And in the PLT Scheme case:

  Composable and Compilable macros
  Matthew Flatt

If I recall correctly Oscar Waddell's thesis is also
worth a read. And I believe Ryan's thesis will be about
macros too."

Of these, I've only had time to seriously look at the first report by
Dybvig, and I like it, as it goes into much more depth than TSPL.

As far as debugging goes, I have found that the following to be useful
(syntax-case foo ()
  ((pattern ...)
   (begin (display #'(syntax stuff))(newline) #'(the macro expansion))))

When DrScheme displays the syntax object she will give you access to all its

Best wishes,
> Grant Rettke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20071018/81ad2913/attachment.html>

Posted on the users mailing list.