[CM] need macro help!

Iain Duncan iainduncanlists at gmail.com
Wed Sep 8 10:38:00 PDT 2021


Thanks Bill, yes that was it. I had figured out that was the (first!) error
before you replied, but my solution was much more rube-goldbergish than
yours, so much appreciated.

Of course now I've realized it needs to be recursive, silly me. (+ %1 %2)
works, but not (+ (+ %1 %2) %3).  gah!

iain

On Wed, Sep 8, 2021 at 10:09 AM <bil at ccrma.stanford.edu> wrote:

> I think the "sexp" argument to map is just the
> macro argument name 'sexp, so map can't figure
> out what to do, and asks make-iterator to do
> something (hence the make-iterator error).  I
> would write the macro:
>
> (define-macro (run-expr sexp)
>    `(eval (map
>           (lambda(token)
>              (if (and (symbol? token)
>                      (eq? ((symbol->string token) 0) #\%))
>                 `(s4m-expr-inputs ,(string->number (substring
> (symbol->string token)
> 1)))
>                 token))
>           ,sexp))
>
> so (s4m-run-expr "(+ %1 %2 %3)") returns 66.
>
> If you omit the eval (to see what code is being generated),
>
>    (s4m-run-expr "(+ %1 %2 %3)")
>
> returns
>
>    (+ (s4m-expr-inputs 1) (s4m-expr-inputs 2) (s4m-expr-inputs 3))
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20210908/5bc6f6e3/attachment-0001.html>


More information about the Cmdist mailing list