D-Programming-Language/phobos — pull request #1255 by someboddy (2013-04-12 19:36:07+00:00)
Title: fix issue 9926 - Add the let function

`let` is a very fundamental building block in functional programming. It's
similar to variable declaration+assignment in imperative programming, but the
name-binding is done mid-expression, and the scope of the binding is limited to
the part of the expression where it is used.

These properties make it beneficial for imperative languages as well, since it
exempts the programmer from having to split a calculation, allowing them to put
a complex calculation with mid-results inside an expression, and to limit the
scope of the mid-results to that calculation.

Example:
```D
functionWithManyArguments(
//Many arguments
(1 + 2 * 3).let!(x => x * x * x + 2 * x * x + 3 * x)(),
//More arguments
);
```
Instead of:
```D
int x = 1 + 2 * 3;
functionWithManyArguments(
//Many arguments
x * x * x + 2 * x * x + 3 * x,
//More arguments
);
```

Without the `let` function, not only are we forced to split the calculation and
put some of it before the call to `functionWithManyArguments`, but we are also
exposing the mid-result `x` that can be used in later parts of the program -
even though it is only needed for this calculation.

See http://d.puremagic.com/issues/show_bug.cgi?id=9926