Version: 4.2.1

13.3 The scheme/load Language

 #lang scheme/load

The scheme/load language supports traditional Scheme evaluation, where each top-level form in the module body is separately passed to eval in the same way as for load.

The namespace for evaluation shares the module registry with the scheme/load module instance, but it has a separate top-level environment, and it is initialized with the bindings of scheme. A single namespace is created for each instance of the scheme/load module (i.e., multiple modules using the scheme/load language share a namespace). The scheme/load library exports only #%module-begin and #%top-interaction forms that effectively swap in the evaluation namespace and call eval.

For example, the body of a module using scheme/load can include module forms, so that running the following module prints 5:

  #lang scheme/load
  
  (module m scheme/base
    (provide x)
    (define x 5))
  
  (module n scheme/base
    (require 'm)
    (display x))
  
  (require 'n)

Definitions in a module using scheme/load are evaluated in the current namespace, which means that load and eval can see the definitions. For example, running the following module prints 6:

  #lang scheme/load
  
  (define x 6)
  (display (eval 'x))

Since all forms within a scheme/load module are evaluated in the top level, bindings cannot be exported from the module using provide. Similarly, since evaluation of the module-body forms is inherently dynamic, compilation of the module provides essentially no benefit. For these reasons, use scheme/load for interactive exploration of top-level forms only, and not for constructing larger programs.