Skip to content

Commit

Permalink
Added extra context in the nested string interpolation example (#1070)
Browse files Browse the repository at this point in the history
* Added extra context in the nested string interpolation example because the string + operator was not previously introduced

Co-authored-by: Valentin Gagarin <valentin@gagarin.work>
  • Loading branch information
ellyxir and fricklerhandwerk authored Nov 7, 2024
1 parent 666b942 commit ac38abe
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions source/tutorials/nix-language.md
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,33 @@ in
"no no no"
```

:::{dropdown} Detailed explanation
Any Nix expression where the value can be represented as a string can be used within `${ }`.

The `+` sign in the above expression is the [string concatenation operator](https://nix.dev/manual/nix/latest/language/operators#string-concatenation), which takes two strings and produces a new string.

The expression in the example is deliberately confusing in order to demonstrate that arbitrarily nested string interpolations are possible, but tend to be hard to read.

It denotes a string that contains the interpolation of concatenating the value of `a` with a string that starts with a space and is followed by another interpolated string.
That second interpolated string is again the result of concatenating the value of `a` and yet another string that starts with a space and is followed by an interpolation of `a`.

Example:
```{code-block} nix
:class: expression
let
a = "one";
b = "two";
in
"${a + b}"
```

```{code-block}
:class: value
"onetwo"
```

Built-in functions are discussed in a [later section](libraries).
:::

:::{warning}
You may encounter strings that use the dollar sign (`$`) before an assigned name, but no braces (`{ }`):
Expand Down

0 comments on commit ac38abe

Please sign in to comment.