On Nov 9, 2008, at 8:56 AM, marcomaggi wrote:

Help a guy out!

Both because I need it and as an exercise in learning
SYNTAX-CASE I have tried for hours to write a Common
Lisp like DEFINE-MACRO.  I could not get around how to
use/modify/whatever:

(define lisp-transformer
  (lambda (p)
    (lambda (x)
      (syntax-case x ()
        ((keyword . rest)
         (datum->syntax (syntax keyword)
                        (p (syntax->datum x))))))))

Put that definition in a library (lisp-transformer) like:

(library (lisp-transformer)
  (export lisp-transformer)
  (import (rnrs))
  (define lisp-transformer
    (lambda (p)
      (lambda (x)
        (syntax-case x ()
          ((keyword . rest)
           (datum->syntax (syntax keyword)
             (p (syntax->datum x)))))))))

then import that library, and do:

> (import (lisp-transformer))
> (define-syntax foo
    (lisp-transformer
      (lambda (x)
        `(cons ,(cadr x) ,(caddr x)))))
> (foo 1 2)
(1 . 2)
> (let ([cons +]) (foo 1 2))
3

If you're going to learn syntax-case, I don't think you should be
doing lisp macros like the one above.

Aziz,,,

Reply via email to