[plt-scheme] simple macro
Eli,Joe,
Thanks for the help.
After Eli's message I decided to go with the
approach Joe's suggested.
Cheers
David
-------------- Original message ----------------------
From: Joe Marshall <jrm at ccs.neu.edu>
> Eli Barzilay <eli at barzilay.org> writes:
>
> > For list-related administrative tasks:
> > http://list.cs.brown.edu/mailman/listinfo/plt-scheme
> >
> > On Mar 2, David J. Neu wrote:
> >>
> >> (define-syntax init
> >> (syntax-rules ()
> >> ((_ sym def) (cond ((assq (quote sym) args) => cadr)
> >> (else def)))))
>
>
> > This will work:
> >
> > (define-syntax (init stx)
> > (syntax-case stx ()
> > [(_ sym def)
> > (with-syntax ([args (datum->syntax-object stx 'args stx)])
> > #'(cond [(assq (quote sym) args) => cadr]
> > (else def)))]))
>
> As will passing ARGS in to the macro:
>
> (define-syntax init
> (syntax-rules ()
> ((_ sym def args) (cond ((assq (quote sym) args) => cadr)
> (else def)))))
>
> (define f
> (lambda (x . args)
> (let ((y (init y 2 args)))
> (printf "x=~a y=~a~n" x y))))
>
>