[Nix-dev] Attribute selection with default

nicolas.b.pierron nicolas.b.pierron at gmail.com
Thu Sep 24 16:39:44 CEST 2009


On Thu, Sep 24, 2009 at 16:24, Eelco Dolstra <e.dolstra at tudelft.nl> wrote:
> 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.

The "?" is associated to attribute possession,  Thus I think it should
appear somewhere in the operator.  The problem with the "or" operator
is that you except an "and" operator et that it could be confused with
logical operators of other languages:

1/ if set ? attr && set.attr then .. else ..

2/ if set.attr or false then .. else ..

3/ if set.{attr ? false} then .. else ..

The first thing I want to do when I see (2) is removing the "or false"
because this is pointless in other languages.  The (3) syntax looks
like ` set@{attr ? default} ' and seems straight-forward because the
question mark appear and because we are already hab to see this.


-- 
Nicolas Pierron
http://www.linkedin.com/in/nicolasbpierron
Andrew S. Tanenbaum - Never underestimate the bandwith of a wagon full of tapes.



More information about the nix-dev mailing list