[plt-scheme] How best to iterate arguments to a macro?

From: Chongkai Zhu (czhu at cs.utah.edu)
Date: Sat Oct 20 20:07:40 EDT 2007

Your solution is OK.

If you don't want to have recursive macro expanding, here's another 
solution:

(define-syntax (property stx)
  (syntax-case stx ()
    ((property)
     (raise-syntax-error 'property "Please provide at least one name" 
'{property ?}))
    ((_ name ...)
     (with-syntax (((property-name ...)
                    (generate-temporaries #'(name ...))))
       #'(begin
           (define property-name null) ...
           (define/public name
             (case-lambda
               [() property-name]
               [(value) (set! property-name value)]))
           ...)))))

Chongkai


Grant Rettke wrote:
> I wanted a macro to declare class level properties and came up with
> the macro 'property'. Its applications looks like this:
>
> (define service-call%
>   (class* object% ()
>     (property customer-name customer-id call-type-code date-of-call-string)
>     (super-new)))
>
> Working on this I wasn't sure whether to use variable arguments or
> ellipses to specify the pattern. I ended up using ellipses. Is it even
> possible to iterate using variable arguments?
>
> My question for everyone is in cases like this, what is the best way
> to iterate arguments when you are going to perform the same operation
> on each argument?
>
> Here is my solution:
>
> (define-syntax property
>   (syntax-rules ()
>     ((_) (raise-syntax-error 'property "Please provide at least one
> name" '{property ?}))
>     ((_ name)
>      (begin
>        (define property-name null)
>        (define/public name
>          (case-lambda
>            [() property-name]
>            [(value) (set! property-name value)]))))
>     ((_ name names ...)
>      (begin
>        (property name)
>        (property names ...)))))
> _________________________________________________
>   For list-related administrative tasks:
>   http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>   



Posted on the users mailing list.