From: Jonathan S. S. <sh...@er...> - 2008-01-22 03:48:22
|
On Mon, 2008-01-21 at 22:40 -0500, Tom Breton (Tehom) wrote: > > However, note that there is an inherent ambiguity about what LOAD means > > when it is called from any place that is not top level. Specifically: > > the LOAD will internally execute a REPL loop, and it is not obvious what > > environment that REPL loop runs in? In particular, does it's environment > > (if not specified explicitly as an argument to LOAD) include any > > non-globals that were bound in the procedure calling LOAD? > > > > I don't know the answer, and the standard does not take a position. > > I don't know, but what makes sense to me is to use the environment load > was called in. Actually, I think that this is exactly the wrong thing to do. In the absence of specification, LOAD should be called with the TOP-LEVEL environment, not the current lexical environment. Rationale: The in-procedure case introduces misleading complexity. Calling load form a procedure is generally a mistake. The cases we want to consider are of the form: (load "a.scm") (load "b.scm") ; must be able to reference results of a.scm (if (test) (load "c.scm) #f) If you see a load within a procedure of the form (load "x.scm" (current-environment)) well, then, the user said "current lexical env" and fuck 'em if they can't take a joke. But in the absence of an argument I claim that the local ENV must NOT be captured "by magic". If you accept this, then the two credible rewritings are: (load "x.scm") => (load "x.scm" (r5rs-environment)) (load "x.scm") => (load "x.scm" (top-level-environment)) I claim that the second is the correct interpretation, because otherwise we must conclude that (load "a.scm") (load "b.scm") => (load "a.scm" (r5rs-environment)) (load "b.scm" (r5rs-environment)) and it would follow generally that later loads cannot use the results of earlier loads -- which is obviously not what we intend. shap |