[plt-scheme] Check syntax and macros

From: Grant Rettke (grettke at acm.org)
Date: Thu Oct 18 09:03:28 EDT 2007

On 10/18/07, Jens Axel Soegaard <jensaxel at soegaard.net> wrote:
> You need to provide a concrete example in order to get a reasonable
> answer.

Understood. The macro is called 'property'; it creates properties in classes.

(require (lib "class.ss"))

(define service-call%
  (class* object% ()
    (property customer-name)
    (property customer-id)
    (property call-type-code)
    (property date-of-call-string)
    (super-new)))

(define-syntax property
  (lambda (stx)
    (define gen-id ; Source: _TSPL3rdEd_ by Kent Dybvig
      (lambda (template-id . args)
        (datum->syntax-object
         template-id
         (string->symbol
          (apply
           string-append
           (map
            (lambda (x)
              (if (string? x) x
                  (symbol->string (syntax-object->datum x))))
            args))))))
    (syntax-case stx ()
      [(_ name)
       (with-syntax
           ([property-name (gen-id (syntax name) "field-" (syntax name))])
         (syntax
          (begin
            (field (property-name null))
            (define/public (name . args)
              (if (null? args) property-name
                  (set! property-name (car args)))))))])))


Posted on the users mailing list.