[plt-scheme] simple macro

From: David J. Neu (djneu at att.net)
Date: Wed Mar 2 17:47:31 EST 2005




 (define-syntax init
  (syntax-rules ()
    ((_ sym def) (cond ((assq (quote sym) args) => cadr)
                       (else def)))))

 (define f
   (lambda (x . args)
     (let  ((y (init y 2)))
       (printf "x=~a y=~a~n" x y))))

(f 1 '(y 3))

reference to undefined identifier: args
/tmp/test.ss:3:42: args
/tmp/test.ss:3:24: (assq (quote y) args)
/tmp/test.ss:8:15: (let-values (((g28) (assq (quote y) args))) (if g28 (cadr g28) (begin 2)))
/tmp/test.ss:8:5: (let-values (((y) (let-values (((g28) (....))) (if g28 ....)))) (printf "x=~a y=~a~n" x y))



Posted on the users mailing list.