[plt-scheme] simple macro
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))))