[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Question about load.



    Date: Tue, 29 Dec 87 14:40:01 +0100
    From: Oliver Laumann <net%TUB.BITNET at MITVMA.MIT.EDU>

    The R3RS does not specify in which environment definitions loaded
    from a file will be bound.  Consider the following function:

        (define (f) (load "foo"))

    where "foo" contains the definition

        (define x 9).

    When "f" is invoked, is the variable "x" put into the environment frame
    created by the call to "f", that is, is it made a local variable,
    or is it entered into the environment frame in which "f" has been
    defined?
    I personally would expect the former, but this would make it impossible
    to write a function similar to "require" supported by Gnu-Emacs.
    C-Scheme seems to load definitions into the environment employed by
    the read-eval-print loop, which is more useful (but less obvious).

Scheme is lexically scoped, and LOAD is a procedure, therefore there's
no way that LOAD could find out the environment from which it was
called.  Thus it has to get an environment from somewhere else, e.g. the
current global state of the read-eval-print loop.  C Scheme and T
both have this semantics.

    What is your opinion about this and how is it handled by existing
    interpreters?  In interpreters that support environments as first-class
    objects (like C-Scheme), shouldn't "load" receive a second argument --
    the environment in which the contents of the file will be evaluated?

C-Scheme and T both do indeed accept an environment as an optional
second argument to LOAD.