[plt-scheme] Struggling with macro...

From: Robert Nikander (nikander at nc.rr.com)
Date: Wed May 23 10:42:52 EDT 2007

Paulo J. Matos wrote:
> On 5/23/07, Jos K oot <jos.koot at telefonica.net> wrote:
>> Hi
>> The ellipsis in the inner macro, it is handled by the outer macro. In 
>> order
>> to push the ellipsis into the inner macro replace it by (... ...) 
>> which is a
>> kind of quoting an ellipsis within a pattern or template.
> 
> Yes, I've read about it... so I guess the following should work even
> though is pretty cryptic:
> (define-syntax (machine stx)
>    (syntax-case stx ()
>      [(_ mname sexps ...)
>       (identifier? #'mname) ; fender
>       #`(let ([mc (make-mc () () () () ())])
>           #,(with-syntax ([variables (syntax-case #'(sexps ...) (variables)
>                                        (((variables (name value) (...
> ...)) (... ...))
>                                         (andmap identifier? #'(name (... 
> ...)))
>                                         ((add-variable-to-mc #'mc
> #'name #'value) (... ...))))])
>               #'variables
>               #'mc))]))
> 

It doesn't look like you need (... ...) in this case, because you are 
not nesting syntax.  You usually need the (... ...) when you are 
defining macros that define macros.  Eg:

;; Macro that defines a macro that works like "begin"
(define-syntax define-begin-alias
   (syntax-rules ()
     ((_ name)
      (define-syntax name
        (syntax-rules ()
          ((_ body (... ...))
           (begin body (... ...))))))))

(define-begin-alias doit)

(doit
  (printf "yabba~n")
  (printf "dabba~n")
  'done)

Rob




Posted on the users mailing list.