Nix (language): Difference between revisions

imported>Gabriel-doriath-dohler
No edit summary
imported>Jeff-hykin
m Expand/clarify the "or" operator
Line 143: Line 143:


{| class="wikitable"
{| class="wikitable"
!width="6%"| Prec
!width="6%"| Precedence
!width="13%"| Abbreviation
!width="13%"| Abbreviation
!width="24%"| Example
!width="24%"| Example
Line 151: Line 151:
| 1
| 1
| SELECT
| SELECT
| <code>e . attrpath [or def]</code>
| <syntaxHighlight lang=nix>e . attrpath</syntaxHighlight>
| none
| none
| Select attribute denoted by the attribute path <code>attrpath</code> from set <code>e</code>. (An attribute path is a dot-separated list of attribute names.) If the attribute doesn’t exist, return <code>default</code> if provided, otherwise abort evaluation.
| Select attribute denoted by the attribute path <code>attrpath</code> from set <code>e</code>. (An attribute path is a dot-separated list of attribute names.) If the attribute doesn’t exist abort evaluation.
|-
| 1
| SELECT*
| <syntaxHighlight lang=nix>e . attrpath or defaultVal </syntaxHighlight>
| none
| If the attribute <code>attrpath</code> doesn’t exist, return <code>defaultVal</code>. NOTE: This is a ternary operator, the "or" keyword is only a keyword when used as a part of this ternary operator.
|-
|-
| 2
| 2
| APP
| APP
| <code>e1 e2</code>
| <syntaxHighlight lang=nix>e1 e2</syntaxHighlight>
| left
| left
| Call function <code>e1</code> with argument <code>e2</code>.
| Call function <code>e1</code> with argument <code>e2</code>.
Line 163: Line 169:
| 3
| 3
| NEG
| NEG
| <code>-e</code>
| <syntaxHighlight lang=nix>-e</syntaxHighlight>
| none
| none
| Numeric negation.
| Numeric negation.
Line 169: Line 175:
| 4
| 4
| HAS_ATTR
| HAS_ATTR
| <code>e ? attrpath</code>
| <syntaxHighlight lang=nix>e ? attrpath</syntaxHighlight>
| none
| none
| Test whether set <code>e</code> contains the attribute denoted by <code>attrpath</code>; return true or false.
| Test whether set <code>e</code> contains the attribute denoted by <code>attrpath</code>; return true or false.
Line 175: Line 181:
| 5
| 5
| CONCAT
| CONCAT
| <code>e1 ++ e2</code>
| <syntaxHighlight lang=nix>e1 ++ e2</syntaxHighlight>
| right
| right
| List concatenation.
| List concatenation.
Line 181: Line 187:
| 6
| 6
| MUL
| MUL
| <code>e1 * e2</code>
| <syntaxHighlight lang=nix>e1 * e2</syntaxHighlight>
| left
| left
| Numeric multiplication.
| Numeric multiplication.
Line 187: Line 193:
| 6
| 6
| DIV
| DIV
| <code>e1 / e2</code>
| <syntaxHighlight lang=nix>e1 / e2</syntaxHighlight>
| left
| left
| Numeric division.
| Numeric division.
Line 193: Line 199:
| 7
| 7
| ADD
| ADD
| <code>e1 + e2</code>
| <syntaxHighlight lang=nix>e1 + e2</syntaxHighlight>
| left
| left
| Numeric addition, or string concatenation.
| Numeric addition, or string concatenation.
Line 199: Line 205:
| 7
| 7
| SUB
| SUB
| <code>e1 - e2</code>
| <syntaxHighlight lang=nix>e1 - e2</syntaxHighlight>
| left
| left
| Numeric subtraction.
| Numeric subtraction.
Line 205: Line 211:
| 8
| 8
| NOT
| NOT
| <code>!e</code>
| <syntaxHighlight lang=nix>!e</syntaxHighlight>
| left
| left
| Boolean negation.
| Boolean negation.
Line 211: Line 217:
| 9
| 9
| UPDATE
| UPDATE
| <code>e1 // e2</code>
| <syntaxHighlight lang=nix>e1 // e2</syntaxHighlight>
| right
| right
| Return a set consisting of the attributes in <code>e1</code> and <code>e2</code> (with the latter taking precedence over the former in case of equally named attributes).
| Return a set consisting of the attributes in <code>e1</code> and <code>e2</code> (with the latter taking precedence over the former in case of equally named attributes).
Line 217: Line 223:
| 10
| 10
| LT
| LT
| <code>e1 &lt; e2</code>
| <syntaxHighlight lang=nix>e1 > e2</syntaxHighlight>
| left
| left
| Less than.
| Less than.
Line 223: Line 229:
| 10
| 10
| LTE
| LTE
| <code>e1 &lt;= e2</code>
| <syntaxHighlight lang=nix>e1 <= e2</syntaxHighlight>
| left
| left
| Less than or equal.
| Less than or equal.
Line 229: Line 235:
| 10
| 10
| GT
| GT
| <code>e1 &gt; e2</code>
| <syntaxHighlight lang=nix>e1 > e2</syntaxHighlight>
| left
| left
| Greater than.
| Greater than.
Line 235: Line 241:
| 10
| 10
| GTE
| GTE
| <code>e1 &gt;= e2</code>
| <syntaxHighlight lang=nix>e1 >= e2</syntaxHighlight>
| left
| left
| Greater than or equal.
| Greater than or equal.
Line 241: Line 247:
| 11
| 11
| EQ
| EQ
| <code>e1 == e2</code>
| <syntaxHighlight lang=nix>e1 == e2</syntaxHighlight>
| none
| none
| Equality.
| Equality.
Line 247: Line 253:
| 11
| 11
| NEQ
| NEQ
| <code>e1 != e2</code>
| <syntaxHighlight lang=nix>e1 != e2</syntaxHighlight>
| none
| none
| Inequality.
| Inequality.
Line 253: Line 259:
| 12
| 12
| AND
| AND
| <code>e1 &amp;&amp; e2</code>
| <syntaxHighlight lang=nix>e1 && e2</syntaxHighlight>
| left
| left
| Logical AND.
| Logical AND.
Line 259: Line 265:
| 13
| 13
| OR
| OR
| <code><nowiki>e1 || e2</nowiki></code>
| <syntaxHighlight lang=nix>e1 || e2</syntaxHighlight>
| left
| left
| Logical OR.
| Logical OR.
Line 265: Line 271:
| 14
| 14
| IMPL
| IMPL
| <code>e1 -&gt; e2</code>
| <syntaxHighlight lang=nix>e1 -> e2</syntaxHighlight>
| none
| none
| Logical implication (equivalent to <code><nowiki>!e1 || e2</nowiki></code>).
| Logical implication (equivalent to <code><nowiki>!e1 || e2</nowiki></code>).