return when desugaring to closures

Peter Michaux petermichaux at
Sat Oct 11 13:36:18 PDT 2008

On Sat, Oct 11, 2008 at 1:21 PM, Mark S. Miller <erights at> wrote:

> The let declaration is in. Like const and function declarations, it
> has block-level letrec lexical scoping. I continue to oppose let
> expressions and let statements, as they don't provide enough
> additional power to justify their cost. For example, if lambda
> supports optional args, as I think we all agree it should, then,
> adapting a suggestion of Lars, we should define the scope in which the
> default value expressions are evaluated so that
>    var x = 2;
>    (lambda (x = 3, y = x) (x+y))()


(lambda (x = 3, y = x) (x+y))()

to just

let (x = 3, y = x) (x+y)

makes it much more clear when reading code what the intention of the
programmer was. The reader doesn't need to interpret the code with as
many steps and doesn't need to check at the end of the expression to
see if the lambda is immediately called or not. This checking is an
issue when an immediately called lambda spans more than a screen.
Repeatedly writing the whole immediately-called, anonymous function is
boilerplate for such a common pattern. I admit it is not much
character boiler plate but it is the fact that the pattern is so
common that I believe the concept is worth abstracting. It is the
mental boilerplate that is the waste.


More information about the Es-discuss mailing list