guile-devel
[Top][All Lists]
Advanced

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

Re: A plea for local-eval in 2.0.4


From: Mark H Weaver
Subject: Re: A plea for local-eval in 2.0.4
Date: Sat, 14 Jan 2012 11:17:23 -0500
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

David Kastrup <address@hidden> writes:
> within local-eval, what is the return value of calling
> (current-module)?  I would expect that it is the same as outside of
> local-eval

Actually, this is not true.  Within `local-eval', (current-module) is
temporarily restored (using dynamic-wind) to the module saved in the
lexical environment.

This is probably not optimal.  Among other things, it breaks the nice
equivalence <expr> == (local-eval '<expr> (the-environment)), but
`local-eval' and `local-compile' are based on `eval' and `compile', and
this is what `eval' and `compile' do (for some reason unknown to me).

> so that (define x 5) inside of local-eval

As Andy pointed out, I deliberately restrict the form passed to
`local-eval' (or `local-compile') to be an _expression_.  (define x 5)
is not an expression; it is a definition.  I explained the reason for
this restriction a few days ago[1] on this list.

> would _not_ be equivalent to (module-define! (current-module) 'x 5) as
> the first one would take the current module at the-environment time,
> and the second one would take it at local-eval time.

Actually, because `local-eval' restores (current-module) to the one
saved in the lexical environment, (module-define! (current-module) 'x 5)
within `local-eval' actually defines the variable within the saved
module, i.e. the module used for lookup if you replace (the-environment)
with a top-level variable reference.

      Mark


[1] Message to guile-devel dated 08 Jan 2012 15:39:36 -0500, with
    subject "Re: [PATCH] Implement local-eval, local-compile, and
    the-environment"



reply via email to

[Prev in Thread] Current Thread [Next in Thread]