Nix (language): Difference between revisions

imported>Makefu
good enough i guess
imported>Makefu
add operators
Line 79: Line 79:
# <code>{ x, y ? "foo", z ? "bar", ... }: z + y + x</code> a set pattern, which can also set defaults. ellipse means that the function may receive extra arguments.
# <code>{ x, y ? "foo", z ? "bar", ... }: z + y + x</code> a set pattern, which can also set defaults. ellipse means that the function may receive extra arguments.
# <code>args@{ x, y, z, ... }: z + y + x + args.a</code> an <code>@</code> pattern which can be used to match extra arguments and store them in the <code>args</code> set.
# <code>args@{ x, y, z, ... }: z + y + x + args.a</code> an <code>@</code> pattern which can be used to match extra arguments and store them in the <code>args</code> set.
=== Operators ===
Lower precedence means a stronger binding; ie. this list is sorted from strongest to weakest binding, and in the case of equal precedence between two operators, the associativity decides the binding.
{| class="wikitable"
!width="6%"| Prec
!width="13%"| Abbreviation
!width="24%"| Example
!width="13%"| Assoc
!width="42%"| Description
|-
| 1
| SELECT
| <code>e . attrpath [or def]</code>
| 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.
|-
| 2
| APP
| <code>e1 e2</code>
| left
| Call function <code>e1</code> with argument <code>e2</code>.
|-
| 3
| NEG
| <code>-e</code>
| none
| Numeric negation.
|-
| 4
| HAS_ATTR
| <code>e ? attrpath</code>
| none
| Test whether set <code>e</code> contains the attribute denoted by <code>attrpath</code>; return true or false.
|-
| 5
| CONCAT
| <code>e1 ++ e2</code>
| right
| List concatenation.
|-
| 6
| MUL
| <code>e1 * e2</code>
| left
| Numeric multiplication.
|-
| 6
| DIV
| <code>e1 / e2</code>
| left
| Numeric division.
|-
| 7
| ADD
| <code>e1 + e2</code>
| left
| Numeric addition, or string concatenation.
|-
| 7
| SUB
| <code>e1 - e2</code>
| left
| Numeric subtraction.
|-
| 8
| NOT
| <code>!e</code>
| left
| Boolean negation.
|-
| 9
| UPDATE
| <code>e1 // e2</code>
| 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).
|-
| 10
| LT
| <code>e1 &lt; e2</code>
| left
| Less than.
|-
| 10
| LTE
| <code>e1 &lt;= e2</code>
| left
| Less than or equal.
|-
| 10
| GT
| <code>e1 &gt; e2</code>
| left
| Greater than.
|-
| 10
| GTE
| <code>e1 &gt;= e2</code>
| left
| Greater than or equal.
|-
| 11
| EQ
| <code>e1 == e2</code>
| none
| Equality.
|-
| 11
| NEQ
| <code>e1 != e2</code>
| none
| Inequality.
|-
| 12
| AND
| <code>e1 &amp;&amp; e2</code>
| left
| Logical AND.
|-
| 13
| OR
| <code><nowiki>e1 || e2</nowiki></code>
| left
| Logical OR.
|-
| 14
| IMPL
| <code>e1 -&gt; e2</code>
| none
| Logical implication (equivalent to <code><nowiki>!e1 || e2</nowiki></code>).
|}
Source: [https://gist.github.com/joepie91/c3c047f3406aea9ec65eebce2ffd449d Gist of joepie91]


=== imports ===
=== imports ===