[Nix-dev] confused using the <obj> ? <string> operator with non literal operators
Layus
layus.on at gmail.com
Mon May 9 23:34:01 CEST 2016
I never said it made sense ;-).
But think of it as array access. It is the exact counterpart of the dot
(.) operator :
nix-repl> foo = { bar = 1; }
nix-repl> quux = "bar"
nix-repl> foo?bar
true
nix-repl> foo.bar
1
nix-repl> foo?${quux}
true
nix-repl> foo.${quux}
1
nix-repl> foo?quux
false
nix-repl> foo.quux
error: attribute ‘quux’ missing, at (string):1:1
From that point of view it makes sense, right ?
Now its your turn: What section of the manual should be updated to
better explain this ?
You are at the best place to tell us how you looked for the info, and
where you expected to find it.
-- Layus.
On 09/05/16 16:36, Samuel wrote:
> Oh, I see. So foo ? quux evaluates to foo ? "quux". Seems a bit
> confusing, but everything is clear now :)
>
> Thanks
>
> On 9 May 2016 at 15:52, Guillaume Maudoux (Layus) <layus.on at gmail.com> wrote:
>> You are missing the only command that could enlighten you :
>>
>>> foo ? bar
>> true
>>
>> The second operant is taken as a string literal, that's why you need to
>> evaluate variables there.
>> The following also works :
>>
>>> foo ? ${quux}
>> true
>>
>> -- Layus.
>>
>> Le 09/05/16 à 15:25, Samuel a écrit :
>>> Am I holding some false assumption here? It seems the ? operator has
>>> different behaviour depending on how the right hand side is evaluated:
>>>
>>> nix-repl> foo = { bar = "baz"; }
>>>
>>> nix-repl> quux = "bar"
>>>
>>> nix-repl> foo ? "bar"
>>> true
>>>
>>> nix-repl> foo ? quux
>>> false
>>>
>>> nix-repl> foo ? "${quux}"
>>> true
>>>
>>> nix-repl> quux == "${quux}"
>>> true
>>>
>>> nix-repl> builtins.typeOf quux
>>> "string"
>>>
>> _______________________________________________
>> nix-dev mailing list
>> nix-dev at lists.science.uu.nl
>> http://lists.science.uu.nl/mailman/listinfo/nix-dev
>
>
More information about the nix-dev
mailing list