David Kastrup <d...@gnu.org> writes:

> (define current-module
>   (let ((top-level (the-environment)))
>     (lambda () (eval '(the-environment) top-level))))

Some more notes about the above code (changing `eval' ==> `local-eval'):

* (local-eval '(the-environment) <environment>) is a no-op: it always
  returns the same environment that was passed in, so there's no point
  in doing it.

* Of course `top-level' is a constant, and would be even if it were
  within the (lambda () ...) because it captures no lexicals.  It is
  always in the same module, i.e. the module containing the above
  definition.  This same constant value is always returned by
  (current-module).

* Also note that the real `current-module' simply accesses a fluid,
  which can also be set by `set-current-module'.  (Fluids are a scheme
  analogue to "dynamically-scoped" variables in Lisp).  Conceptually, it
  is variable that is explicitly set by the user.  It has no relation to
  the code that is currently executing.  Rather, it is used during
  compilation (or within a REPL) to keep track of where the user would
  like top-level definitions to go.

     Mark

Reply via email to