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: David Kastrup
Subject: Re: A plea for local-eval in 2.0.4
Date: Sat, 14 Jan 2012 18:20:01 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.92 (gnu/linux)

Mark H Weaver <address@hidden> writes:

> 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).

This is likely going to be a problem.  One can probably fudge around it
with something like
(local-eval `(let ((current-environment (lambda ()
                     ,(current-environment))))
                  ...
but that does not look like it would really prettify things.

>> 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.

Well, use set! amd module-set! then for the example.

> 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.

Looks awkward.  And is not compatible with Guilev1 behavior:

guile> (save-module-excursion (lambda () (let ((env (the-environment))) 
(set-current-module (resolve-module '(none))) (local-eval '(current-module) 
env))))
#<directory (none) b6f7c360>
guile> 


-- 
David Kastrup



reply via email to

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