[Nix-dev] Attribute selection with default

Eelco Dolstra e.dolstra at tudelft.nl
Thu Sep 24 14:22:48 CEST 2009


Hi,

Nicolas Pierron wrote:

>> The "or" syntax seems a bit too different from the other part of the
>> language and can be confused with a logical operator from other
>> languages.

Yes, but it has the advantages of not being an operator (which are never really
intuitive, unless they're basic mathematical operators) and being very short.

>> I often use similar patterns where I act on the presence of an attribute:
>>
>> set ? attr && set.attr <=> attrByPath ["attr"] false set

Yes, that's another common use case.

>> The next question is how to handle multiple level like `attrByPath
>> ["a" "b" "c"] default as', one possible way is to attribute selections
>> inside the name of the selected attribute.
>>
>> as.{a.b.c ? default}

I don't find this more intuitive than "as.a.b.c or default".

Also, given that the question mark already has two different meanings
(unfortunately), it shouldn't be used for a third.

Same goes for {...}, which is also already taken.  {x ? default} looks too much
like a function definition.

> in addition to this sugar, you can add dynamic name computation sugar:
> 
> set.<name>

This is an orthogonal issue (not opposed to it btw), but it would be more
straightforward to just allow

  set."${expr}"

-- 
Eelco Dolstra | http://www.st.ewi.tudelft.nl/~dolstra/



More information about the nix-dev mailing list