1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-28 22:01:15 +02:00

language: Link examples to detail explanations.

Also, warn of the scoping caveats of `with`.
This commit is contained in:
Niklas Hambüchen 2024-04-29 03:57:28 +02:00
parent 2f678331d5
commit 460d8fbaea
2 changed files with 79 additions and 33 deletions

View file

@ -402,7 +402,35 @@ establishes the same scope as
let a = 1; in let a = 2; in let a = 3; in let a = 4; in ...
```
Variables coming from outer `with` expressions *are* shadowed:
```nix
with { a = "outer"; };
with { a = "inner"; };
a
```
Does evaluate to `"inner"`.
## Comments
Comments can be single-line, started with a `#` character, or
inline/multi-line, enclosed within `/* ... */`.
`#` comments last until the end of the line.
`/*` comments run until the next occurrence of `*/`; this cannot be escaped.
## Scoping rules
Nix has constructs with
* dynamic scope
* [`with`](#with-expressions)
* static scope
* [`let`](#let-expressions)
* [`inherit`](#inheriting-attributes)
* function arguments
Static scope takes precedence over dynamic scope.
See [`with`](#with-expressions) for a detailed example.