From c6ac52da70a18564dfa828f782c451354cbd4214 Mon Sep 17 00:00:00 2001 From: Michael Daniels Date: Fri, 19 Dec 2025 17:55:22 -0500 Subject: [PATCH] docs: document older let expression syntax I learned of this from reading Eelco Dolstra's PhD thesis (pp. 69, 73-74). Co-authored-by: Robert Hensing --- doc/manual/source/language/syntax.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/doc/manual/source/language/syntax.md b/doc/manual/source/language/syntax.md index b127aca14..6178fa553 100644 --- a/doc/manual/source/language/syntax.md +++ b/doc/manual/source/language/syntax.md @@ -285,6 +285,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).