[Issue 9926] New: Add the `let` function.
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Apr 12 12:31:26 PDT 2013
http://d.puremagic.com/issues/show_bug.cgi?id=9926
Summary: Add the `let` function.
Product: D
Version: D2
Platform: All
OS/Version: All
Status: NEW
Keywords: pull
Severity: enhancement
Priority: P2
Component: Phobos
AssignedTo: nobody at puremagic.com
ReportedBy: GenericNPC at gmail.com
--- Comment #0 from IdanArye <GenericNPC at gmail.com> 2013-04-12 12:31:24 PDT ---
`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:
functionWithManyArguments(
//Many arguments
(1 + 2 * 3).let!(x => x * x * x + 2 * x * x + 3 * x)(),
//More arguments
);
Instead of:
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.
--
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
More information about the Digitalmars-d-bugs
mailing list