[Nix-dev] Not understanding evaluation of with inside let
Harald van Dijk
harald at gigawatt.nl
Sun May 15 22:25:56 CEST 2016
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
More information about the nix-dev
mailing list