<br><br><div class="gmail_quote">2011/6/18 Matthew Koichi Grimes <span dir="ltr"><<a href="mailto:mkg@cs.nyu.edu">mkg@cs.nyu.edu</a>></span><br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">

You want:<br><br>(define-macro (macro-inc x) (list 'inc x))<br></blockquote><div> <br>or same thing: (define-macro (macro-inc x) `(inc ,x))<br><br></div><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">

(list 'inc x) evaluates at macro-expansion-time as (inc x), which at runtime evaluates to what you want.<br><br>The code you wrote does work when entered in interactive mode (gsi); I seem to recall there being a thread in the past month or two about why that might be. I think the gist was that when running non-interactively, gsc does separate passes for macro-expansion, then evaluation. In the macro-expansion pass, it doesn't yet know about functions defined in that file, so calling those functions directly like you did results in an error. On the other hand, in interactive mode, each line gets its own macro-expansion and evaluation pass. So by the time we get to your (define two (macro-inc 1)) line, the macro-expansion pass recognizes 'inc', defined (in the evaluation pass) of an earlier line.<br>



<br>I hope I got that right,<br>-- Matt<div><div></div><div class="h5"><br><br><div class="gmail_quote">On Sat, Jun 18, 2011 at 8:11 AM, Benjohn Barnes <span dir="ltr"><<a href="mailto:benjohn@fysh.org" target="_blank">benjohn@fysh.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0pt 0pt 0pt 0.8ex;border-left:1px solid rgb(204, 204, 204);padding-left:1ex">

<br>
Hi,<br>
<br>
I think I must not be understanding something basic about macro expansion.<br>
<br>
I've reduced a more complex failure with macros that I am having to this simple example:<br>
<br>
> ; Define a function.<br>
> (define (inc x) (+ 1 x))<br>
><br>
> ;Define a macro using the function.<br>
> (define-macro (macro-inc x) (inc x))<br>
><br>
> ; This works okay.<br>
> (define two (inc 1))<br>
><br>
> ; This fails on load with:<br>
> ; *** ERROR IN #<procedure #2>, "macro-test.scm"@5.30 -- Unbound variable: inc<br>
> (define macro-two (macro-inc 1))<br>
<br>
If I try to load this in to gsc (or if I import in to bsc), then when I try and use (expand) macro-inc (as shown in the last line), I get an error. It's as if I'm not allowed to use functions I have defined in the expansion of a macro?<br>




<br>
Thanks,<br>
        Benjohn<br>
<font color="#888888"><br>
--<br>
<a href="mailto:benjohn@fysh.org" target="_blank">benjohn@fysh.org</a> - Twitter @benjohnbarnes - Skype benjohnbarnes - Mobile <a href="tel:%2B44%20%280%29%207968%20851%20636" value="+447968851636" target="_blank">+44 (0) 7968 851 636</a><br>


<br>
_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca" target="_blank">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
</font></blockquote></div><br>
</div></div><br>_______________________________________________<br>
Gambit-list mailing list<br>
<a href="mailto:Gambit-list@iro.umontreal.ca">Gambit-list@iro.umontreal.ca</a><br>
<a href="https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list" target="_blank">https://webmail.iro.umontreal.ca/mailman/listinfo/gambit-list</a><br>
<br></blockquote></div><br>