[racket] Macro Assistance

From: Chad Albers (calbers at neomantic.com)
Date: Tue Aug 27 04:33:17 EDT 2013

I'm still trying to grok macros - which are amazing, but hard.  I'd like to
know if it is possible capture part of the following expression

(display (+ 2 (bar (+ 1 2))))

if "bar" is a literal in the macro, I would like to capture body0 as (+ 1
2) and body1 as (display (+ 2 ...)).

This is a totally artificial example.

Here's what I have:

(define-syntax (define-foo stx)
  (syntax-case stx (bar)
    ([_ (name param) (body1 (bar . body0))]
     (syntax (define (name param)
               (body1 (+ 3 . body0)))))))

(define-foo (foof env)
                (display (bar (+ 1 2))))

This works...and expands to.

(define (foof env)
   (display (+ 3 (- 1 (+ 1 2)))))

(Note that -1 has been substitute for the "bar" literal").

This expression fails with "bad syntax"

(define-foo (foog env)
                (display (+3 (bar (- 1 (+ 1 2))))))

I don't seem be to able to capture (display (+3 )) as separate from (bar
(-1 (+ 1 2)))

Is this possible to capture?

Thanks for any help and insights into macros
Chad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20130827/6e047344/attachment.html>

Posted on the users mailing list.