[Nix-dev] Attribute selection with default
Eelco Dolstra
e.dolstra at tudelft.nl
Thu Sep 24 16:24:54 CEST 2009
Hi,
Nicolas Pierron wrote:
>> Also, given that the question mark already has two different meanings
>> (unfortunately), it shouldn't be used for a third.
>
> Meaning of "?":
> - (set ? attr): Check if the set posses an attribute.
> - (set@{attr ? default}: ...): Check if the set posses an attribute,
> otherwise set it to a default value.
> - (set.{attr ? default}) Check if the set posses an attribute and
> return its value, otherwise return the default value.
>
> what I see is that the "?" is associated to a check of the presence of
> the attribute, and when it is placed inside brackets and after the
> attribute this means that you define a default value.
If "?" wasn't already an operator, I would prefer "a.b.c ? default". But
unfortunately that's not the case. Disambiguating this by putting curly braces
around it just looks weird because it makes it look like an attribute set or a
function.
>> Same goes for {...}, which is also already taken. {x ? default} looks too much
>> like a function definition.
>
> Indeed, and that's the reason for it. Keep things familiar and not confusing.
But it's not a function. That's very confusing.
(Not to mention that the Nix syntax for functions isn't particularly clear to
begin with.)
--
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/
More information about the nix-dev
mailing list