[plt-scheme] help with thin wrapper around class.ss

From: Jon Rafkind (workmin at ccs.neu.edu)
Date: Sun Oct 22 02:18:39 EDT 2006

I'm trying to write some syntax that thinly wraps class.ss to give the 
users less choice, Basically it only allows a set of fields and public 
methods. I figured this would be simpler than writing my own 
pseudo-object system. Most methods should expand to define/public but 
some methods are declared in a base class and if the user overrides them 
then they should expand to define/override. Im not quite sure how to do 
this though.

(define-syntax (define-object stx)
    (syntax-case stx (define)
      ((_ name (var ...)
      (define (method args ...) body ...) ...)
       ;; set all fields as #f to begin with
       (with-syntax (((inits ...) (map (lambda (n) (list n #f))
                      (syntax->list #'(var ...))))
             ((defines ...) (map (lambda (n)
                       (syntax-case n ()
                         ((shapes) #'define/override)
                         ((can-collide) #'define/override)
                         (else #'define/public)))
                     (syntax->list (syntax method ...)))))
         #'(define name
         (class* basic2 ()
           (super-new)
           (init-field inits ...)
           (define/public (method args ...)
                  body ...) ...))))

Which gives the error: syntax: bad form in: (syntax method ...)
I wanted to somehow map each method to either define/public or 
define/override and then use it below in the class* part. What I have 
there is a total guess, and probably totally wrong. Also fields expand 
to (init-field (f1 #f) (f2 #f)). Heres a short example in case Im not 
clear enough:

(define-object my-object (x y z)
   (define (something arg)
     ...)
   (define (stuff)
     ...))


Posted on the users mailing list.