[CM] need macro help!

Iain Duncan iainduncanlists at gmail.com
Wed Sep 8 09:38:40 PDT 2021


I am apparently in over my head, I'm pretty darned new to defmacro'ing. If
anyone can help with this, it would help me add a very nice ability to
scheme for max!

thanks!

; desired behaviour
; (s4m-run-expr "(+ %1 %2 %3)")
; should run as (+1 (expr-ins 1) (expr-ins 2) (expr-ins 3))

; error i get:
;make-iterator argument, input-sexp, is a symbol but should be a sequence
;    (cons 'eval (list (map (lambda...

; these get set elsewhere and represent values that
; will expand %1 %2 etc
(define s4m-expr-inputs (vector '() 11 22 33))

(define (string->sexp text)
  "convert a string of an sexp to an sexp"
  (read (open-input-string text)))

(define-macro (run-expr sexp)
  (cons 'eval (list
    (map
      (lambda(token)
        (if (and (symbol? token) (eq? ((symbol->string token) 0) #\%))
          `(s4m-expr-inputs ,(string->number (list->string (cdr
(string->list (symbol->string token))))))
          token))
      sexp))))

(define (s4m-run-expr sexp-str)
  (let ((input-sexp (string->sexp sexp-str)))
    (run-expr input-sexp)))
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://cm-mail.stanford.edu/pipermail/cmdist/attachments/20210908/fe7b3ec0/attachment.html>


More information about the Cmdist mailing list