From 19d6d5a16ccbb4d6d38034d3d636180231018ba5 Mon Sep 17 00:00:00 2001 From: Vincent Ambo Date: Wed, 7 Aug 2019 16:08:06 +0100 Subject: Add table with most important Nix operators --- nix/nix-1p/README.md | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/nix/nix-1p/README.md b/nix/nix-1p/README.md index 93d1c896b2..ef3e97ae1d 100644 --- a/nix/nix-1p/README.md +++ b/nix/nix-1p/README.md @@ -15,6 +15,7 @@ important is missing. - [Overview](#overview) - [Language constructs](#language-constructs) - [Primitives / literals](#primitives--literals) + - [Operators](#operators) - [Variable bindings](#variable-bindings) - [Functions](#functions) - [Multiple arguments (currying)](#multiple-arguments-currying) @@ -104,6 +105,28 @@ second line rec { a = 15; b = a * 2; } ``` +## Operators + +Nix has several operators, most of which are unsurprising: + +| Syntax | Description | +|----------------------|-----------------------------------------------------------------------------| +| `+`, `-`, `*`, `/` | Numerical operations | +| `+` | String concatenation | +| `++` | List concatenation | +| `==` | Equality | +| `>`, `>=`, `<`, `<=` | Ordering comparators | +| `&&` | Logical `AND` | +| `\|\|` | Logical `OR` | +| `e1 -> e2` | Logical implication (i.e. `!e1 \|\| e2`) | +| `!` | Boolean negation | +| `set.attr` | Access attribute `attr` in attribute set `set` | +| `set ? attribute` | Test whether attribute set contains an attribute | +| `left // right` | Merge `left` & `right` attribute sets, with the right set taking precedence | + +Make sure to understand the `//`-operator, as it is used quite a lot and is +probably the least familiar one. + ## Variable bindings Bindings in Nix are introduced locally via `let` expressions, which make some -- cgit 1.4.1