On Wed, 8 Sep 2021, Iain Duncan wrote:

(define (s4m-process-sexp sexp)

It is entirely a point of style, but I think I would rather make a 'deepmap' helper function. Untested, but something like:

(define (deepmap f x)
  (if (not (list? x))
    (f x)
    (cons (deepmap f (car x))
          (deepmap f (cdr x)))))

This also has the convenient side effect of allowing you to e.g. avoid the contents of quotes.

I also noticed I could thus dispense with the oneline macro all together now by 
doing:

(define (s4m-run-expr sexp-str)
  (let ((input-sexp (string->sexp sexp-str)))
    (eval '(eval (s4m-process-sexp input-sexp)))))

The problem with this is that, since the eval runs in the s4m-run-expr's environment, you lose the lexical scope of the caller. It would be nice to be able to say (let ((x 5)) (s4m-run-expr "something with x"))

I think you can evaluate things in the calling environment with a bacro, but that's hardly simpler than a regular macro.

(define-macro (s4m-run-sexp-macro sexp)
  `(eval (s4m-process-sexp ,sexp)))

Can just be:

(define-macro (s4m-run-sexp-macro sexp)
  (s4m-process-sexp sexp))


 -E
_______________________________________________
Cmdist mailing list
[email protected]
https://cm-mail.stanford.edu/mailman/listinfo/cmdist

Reply via email to