[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Macros: One expression => more than one expression?



brk@jenkon.com writes:
 > What I wanted was to be able to type:
 > 
 > (class object%
 > 	(init-fields foo bar baz))
 > 
 > and get:
 > 
 > (class object%
 > 	(init-field foo)
 > 	(init-field bar)
 > 	(init-field baz))

 > I can't see any way to have the one expression expand into multiple
 > expressions.

I don't think there is in the general case, but in this particular
case you can wrap them in "begin":

(require (lib "class.ss"))
(define-syntax init-fields
  (syntax-rules ()
    ((_ fname ...)
     (begin (init-field fname) ...))))
(define a-class
  (class object%
    (init-fields foo bar baz)
    (define/public (sum) (+ foo bar baz))
    (super-instantiate ())))
(send (make-object a-class 1 2 3) sum)

=> 6

This doesn't appear to be documented-- the syntax for "class-clause"
(http://download.plt-scheme.org/doc/200alpha12/html/mzlib/mzlib-Z-H-3.html#%_sec_3.3) 
should include:

    (begin class-clause ...)

although it's clear that this works from the example expansions of
"public*" and "define/public".

--dougo@ccs.neu.edu