Hello list,

I'm having trouble understanding the result of the following (reduced) 
evaluation:

nix-instantiate --eval --expr 'let x = 1; y = with { x = 2; }; x; in y'

I expect the last x to resolve to the one introduced by with, giving a 
result of 2. Instead, it resolves to the one introduced by let, giving a 
result of 1.

I can trivially rewrite this to avoid the whole problem, but I'd like to 
understand the scope rules better. If this behaviour is intended, I 
can't tell from the documentation. It merely says the set e1 ({x = 2;}) 
is introduced into the lexical scope of the expression e2 (x). It does 
not explicitly address what happens when the lexical scope of the 
expression e2 already contains those same keys, but if some elements of 
e1 are *not* introduced into the lexical scope, then I think the 
documentation is somewhat misleading when it says the whole set is 
introduced into the lexical scope.

So what's going on here? Using Nix 1.11.2 if it matters.

Cheers,
Harald van Dijk
_______________________________________________
nix-dev mailing list
[email protected]
http://lists.science.uu.nl/mailman/listinfo/nix-dev

Reply via email to