[plt-scheme] "compile time" action of macros

From: Eli Barzilay (eli at barzilay.org)
Date: Mon Mar 19 08:10:26 EDT 2007

On Mar 19, Chris Wright wrote:
> Hi,
> I can achieve the desired effect (doing a calculation before run-time) with:
> (define-macro (bloop x)
>  (let ((y (add1 x)))
>    `(list ,y)))
> is there a way to do with with syntax-case? (I should, of course, ask
> "How do I do that with syntax case... :)

  (define-syntax (foo stx)
    (syntax-case stx ()
      [(_ x)
       (number? (syntax-e #'x))
       (with-syntax ([y (add1 (syntax-e #'x))])
         #'(list y))]))

(Note that syntax-e is converting a piece of syntax to a number, so
this macro must be used with a syntactic number.)

          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
                  http://www.barzilay.org/                 Maze is Life!

Posted on the users mailing list.