<div dir="ltr">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<div><br></div><div>(display (+ 2 (bar (+ 1 2))))<br></div><div>
<br></div><div style>if "bar" is a literal in the macro, I would like to capture body0 as (+ 1 2) and body1 as (display (+ 2 ...)). </div><div><br></div><div style>This is a totally artificial example.</div><div>
<br></div><div style>Here's what I have:</div><div style><br></div><div style><div>(define-syntax (define-foo stx)</div><div> (syntax-case stx (bar)</div><div> ([_ (name param) (body1 (bar . body0))]</div><div> (syntax (define (name param)</div>
<div> (body1 (+ 3 . body0)))))))</div><div><br></div><div>(define-foo (foof env)<br></div><div> (display (bar (+ 1 2))))</div><div><br></div><div style>This works...and expands to.</div><div style>
<br></div><div style>(define (foof env)</div><div style> (display (+ 3 (- 1 (+ 1 2)))))<br></div><div style><br></div><div style>(Note that -1 has been substitute for the "bar" literal"). </div><div style>
<br></div><div style>This expression fails with "bad syntax"</div><div style><br></div><div style><div>(define-foo (foog env)<br></div><div> (display (+3 (bar (- 1 (+ 1 2))))))</div><div><br></div>
<div style>I don't seem be to able to capture (display (+3 )) as separate from (bar (-1 (+ 1 2)))</div><div style><br></div><div style>Is this possible to capture?</div><div style><br></div><div style>Thanks for any help and insights into macros</div>
<div style>Chad</div></div></div><div style><br></div></div>