diff --git a/doc/manual/release-notes.xml b/doc/manual/release-notes.xml index cc04a5d808..a4a4f50344 100644 --- a/doc/manual/release-notes.xml +++ b/doc/manual/release-notes.xml @@ -118,6 +118,9 @@ irreversible. the availability of primop in a backwards-compatible way. + Real let-expressions: let x = ...; + ... z = ...; in .... + diff --git a/doc/manual/writing-nix-expressions.xml b/doc/manual/writing-nix-expressions.xml index ea719190f3..74ef3a868e 100644 --- a/doc/manual/writing-nix-expressions.xml +++ b/doc/manual/writing-nix-expressions.xml @@ -716,36 +716,27 @@ encountered).. -Let expressions +Let-expressions -A let expression is a simple short-hand for a -rec expression followed by an attribute selection: -let { attrs } translates -to rec { attrs -}.body. - -For instance, +A let-expression allows you define local +variables for an expression. For instance, -let { +let x = "foo"; y = "bar"; - body = x + y; -} +in x + y -is equivalent to - - -rec { - x = "foo"; - y = "bar"; - body = x + y; -}.body - -and evaluates to "foobar". +evaluates to "foobar". +There is also an obsolete form of let-expression, +let { attrs }, which is +translated to rec { attrs +}.body. That is, the body of the let-expression is the +body attribute of the attribute set. + @@ -757,13 +748,13 @@ propagate attributes). This can be shortened using the inherit keyword. For instance, -let { +let x = 123; - body = { +in + { inherit x; y = 456; - }; -} + } evaluates to {x = 123; y = 456;}. (Note that this works because x is added to the lexical scope by @@ -819,10 +810,8 @@ function calls. a name, you can bind them to an attribute, e.g., -let { - concat = {x, y}: x + y; - body = concat {x = "foo"; y = "bar";}; -} +let concat = {x, y}: x + y; +in concat {x = "foo"; y = "bar";} @@ -837,11 +826,9 @@ where var is the name of the argument. It is not possible to define a default. Example: -let { - negate = x: !x; - concat = x: y: x + y; - body = if negate true then concat "foo" "bar" else ""; -} +let negate = x: !x; + concat = x: y: x + y; +in if negate true then concat "foo" "bar" else "" Note that concat is a function that takes one arguments and returns a function that takes another argument. This @@ -849,7 +836,7 @@ allows partial parameterisation (i.e., only filling some of the arguments of a function); e.g., - map (concat "foo") ["bar", "bla", "abc"] +map (concat "foo") ["bar", "bla", "abc"] evaluates to ["foobar" "foobla" "fooabc"]. @@ -958,9 +945,9 @@ used in the Nix expression for Subversion. -With expressions +With-expressions -A with expression, +A with-expression, with e1; e2 @@ -970,11 +957,8 @@ lexical scope of the expression e2. For instance, -let { - as = {x = "foo"; y = "bar";}; - - body = with as; x + y; -} +let as = {x = "foo"; y = "bar";}; +in with as; x + y evaluates to "foobar" since the with adds the x and