Home Explore Blog CI



nix

3rd chunk of `doc/manual/source/language/index.md`
31ee18963f5bdba06c7e5377a452f87e1f15810d303bf4100000000100000857
  <td>

   Boolean negation

  </td>
 </tr>
 <tr>
  <td>

   `{ x = 1; y = 2; }.x`

  </td>
  <td>

   [Attribute selection](@docroot@/language/types.md#attribute-set) (evaluates to `1`)

  </td>
 </tr>
 <tr>
  <td>

   `{ x = 1; y = 2; }.z or 3`

  </td>
  <td>

   [Attribute selection](@docroot@/language/types.md#attribute-set) with default (evaluates to `3`)

  </td>
 </tr>
 <tr>
  <td>

   `{ x = 1; y = 2; } // { z = 3; }`

  </td>
  <td>

   Merge two sets (attributes in the right-hand set taking precedence)

  </td>
 </tr>
 <tr>
  <td>

   *Control structures*

  </td>
  <td>



  </td>
 </tr>
 <tr>
  <td>

   `if 1 + 1 == 2 then "yes!" else "no!"`

  </td>
  <td>

   [Conditional expression](@docroot@/language/syntax.md#conditionals).

  </td>
 </tr>
 <tr>
  <td>

   `assert 1 + 1 == 2; "yes!"`

  </td>
  <td>

   [Assertion](@docroot@/language/syntax.md#assertions) check (evaluates to `"yes!"`).

  </td>
 </tr>
 <tr>
  <td>

   `let x = "foo"; y = "bar"; in x + y`

  </td>
  <td>

   Variable definition. See [`let`-expressions](@docroot@/language/syntax.md#let-expressions).

  </td>
 </tr>
 <tr>
  <td>

   `with builtins; head [ 1 2 3 ]`

  </td>
  <td>

   Add all attributes from the given set to the scope (evaluates to `1`).

   See [`with`-expressions](@docroot@/language/syntax.md#with-expressions) for details and shadowing caveats.

  </td>
 </tr>
 <tr>
  <td>

   `inherit pkgs src;`

  </td>
  <td>

   Adds the variables to the current scope (attribute set or `let` binding).
   Desugars to `pkgs = pkgs; src = src;`.
   See [Inheriting attributes](@docroot@/language/syntax.md#inheriting-attributes).

  </td>
 </tr>
 <tr>
  <td>

   `inherit (pkgs) lib stdenv;`

  </td>
  <td>

   Adds the attributes, from the attribute set in parentheses, to the current scope (attribute set or `let` binding).
   Desugars to `lib = pkgs.lib; stdenv = pkgs.stdenv;`.
   See [Inheriting attributes](@docroot@/language/syntax.md#inheriting-attributes).

  </td>
 </tr>
 <tr>
  <td>

   *[Functions](@docroot@/language/syntax.md#functions) (lambdas)*

  </td>
  <td>



  </td>
 </tr>
 <tr>
  <td>

   `x: x + 1`

Title: Nix Language Examples: Operators, Control Structures, and Functions
Summary
This section continues with examples of Nix language features, focusing on operators, control structures, and functions. It covers boolean negation, attribute selection (with and without defaults), merging attribute sets, conditional expressions, assertions, let-expressions for variable definition, with-expressions for adding attributes to the scope, and inherit-expressions for adding variables to the current scope. Finally, it begins to introduce functions (lambdas).