Hi all, Skyler Ferris writes:
> On 1/23/24 05:37, Mortimer Cladwell wrote: > > When I run the above I get as output: > > > > "varB post cond: B" > > "varC post if: C" > > "varA in main: A" > > "varB in main:" > > "varC in main: C" > > > > Why can I reset the variables with both 'cond' and 'if' in env.scm, but > > only the variable reset with 'if' is exported with the updated value? > > I don't have a complete answer, but it looks like this has to do with > compilation. If I run it like this: > > $ export GUILE_LOAD_PATH=$pwd > $ guile main.scm > > Then I see similar output, except that for me varC has also not been > updated. I am on guile version 3.0.9. > > However, if I first set GUILE_AUTO_COMPILE=0 (and delete the cached > compiled modules) then the main module sees the updated values. > > I'm not sure how imperative code in the top level of a module works when > compiling. It seems like a grey area. I think this has something to do with compilation indeed. More specifically, it is caused by cross module inlining [1]. You probably need to declare your env module as not declarative by setting #:declarative? to #f inside the define-module form of env. I think the compiler inlines varB somehow. Not super sure, I am no Guile expert but you could inspect the assembly for main to see what the compiler did. 1: https://www.wingolog.org/archives/2021/05/13/cross-module-inlining-in-guile 2: https://www.gnu.org/software/guile/manual/html_node/Declarative-Modules.html -- Best, Daniel