I have an R6RS script file containing expressions like this

(letrec ((foo (lambda args body-referencing-foo))) (test expr result))

I want expr and body-referencing-foo to be evaluated in a particular
environment extended with the binding for foo. How would you go about
setting that up? I thought I had a solution involving using a custom
macro in place of letrec, but it doesn't work.

I can get expressions like

(test expr result)

on their own to behave the way I want, by using this macro (among other things)

(define-syntax test-eval
  (syntax-rules ()
    ((_ e)
     (call/cc
       (lambda (k)
         (with-exception-handler
           (lambda (x) (if (and (undefined-violation? x)
                             (memq (condition-who x) valid-exports))
                         (k (condition-who x))
                         (raise x)))
           (lambda () (eval 'e (environment '(rnrs) test-library)))))))))

which gives you an idea of what I want to accomplish. The problem with
this approach is that (environment '(rnrs) test-library) is immutable,
but I need to add the definition of foo somehow.

I look forward to seeing your ideas!

Reply via email to