Mark H Weaver <m...@netris.org> writes: > David Kastrup <d...@gnu.org> 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