How about something like that?
(define (clone-env env) (let ((bindings (environment-bindings env))) (make-top-level-environment (map car bindings) (map cadr bindings)))) 1 ]=> (define foo 1) ;Value: foo 1 ]=> (eq? (the-environment) (clone-env (the-environment))) ;Value:
Edited to add:
I'm not quite sure what you are trying to do, but here is what I did to check above. I created a foo.scm file containing:
(set! foo 2) (define baz (+ foo foo)) baz
Then
1 ]=> (define foo 1) ;Value: foo 1 ]=> (load "foo.scm" (clone-env (the-environment))) ;Loading "foo.scm"... done ;Value: 4 1 ]=> foo ;Value: 1 1 ]=> baz ;Unbound variable: baz ;To continue, call RESTART with an option number: ; (RESTART 3) => Specify a value to use instead of baz. ; (RESTART 2) => Define baz to a given value. ; (RESTART 1) => Return to read-eval-print level 1. 2 error>
source share