mirror of
https://github.com/NixOS/nix.git
synced 2025-12-23 17:31:08 +01:00
Merge pull request #14843 from mdaniels5757/document-old-let-expression-syntax
docs: document older let expression syntax
This commit is contained in:
commit
d85e5dfa60
1 changed files with 21 additions and 0 deletions
|
|
@ -286,6 +286,27 @@ in x + y
|
|||
|
||||
This evaluates to `"foobar"`.
|
||||
|
||||
There is also another, older, syntax for let expressions that should not be used in new code:
|
||||
|
||||
> *let* = `let` `{` *identifier* = *expr* `;` [ *identifier* = *expr* `;`]... `}`
|
||||
|
||||
In this form, the attribute set between the `{` `}` is recursive.
|
||||
|
||||
One of the attributes must have the special name `body`,
|
||||
which is the result of the expression.
|
||||
|
||||
Example:
|
||||
|
||||
```nix
|
||||
let {
|
||||
foo = bar;
|
||||
bar = "baz";
|
||||
body = foo;
|
||||
}
|
||||
```
|
||||
|
||||
This evaluates to "baz".
|
||||
|
||||
## Inheriting attributes
|
||||
|
||||
When defining an [attribute set](./types.md#type-attrs) or in a [let-expression](#let-expressions) it is often convenient to copy variables from the surrounding lexical scope (e.g., when you want to propagate attributes).
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue