Expression closures - use-cases for shortcut lambda syntax(blocks)

Igor Bukanov igor at mir2.org
Wed Mar 21 03:26:10 PDT 2007


On 21/03/07, Lars T Hansen <lth at acm.org> wrote:
> On 3/20/07, Brendan Eich <brendan at mozilla.org> wrote:
> > It's not just aesthetics. Aesthetics is the science of beauty, but
> > usability is what users grok -- not always what is beautiful. IOW,
> > the pile of "function" keywords in the Y combinator:
> >
> > function Y(le) {
> >      return function (f) {
> >          return f(f);
> >      }(function (f) {
> >          return le(function (x) {
> >              return f(f)(x);
> >          });
> >      });
> > }
> The Y combinator is not even remotely a compelling use case  for
> ECMAScript.  ;-)  More compelling are those that have already been
> posted in this thread, and as I wrote before, I didn't find those very
> compelling either.

Yet Y combinator is a useful boundary case to test syntax proposals
that in fact caused me to cool for the proposal. Here are the
alternatives:

function(le) (function(f) f(f))(function(f) le(function(x) f(f)(x)))

le => (f => f(f))(f => le(x => f(f)(x)))

Both are better then the original version and it seems that "name =>
expr" is significantly less clattered than the "function (name) exp"
case. But I remember when I saw for the first time Y code written in
Haskell (which is much more suited to write that kind stuff) then to
grasp the idea I had to rewrite it using:

function selfApply(f) f(f)

which gives for the combinator:

function(le) selfApply(function(f) le(function(x) f(f)(x)))

le => selfApply(f => le(x => f(f)(x)))

Now the "=>" case does not look that much better and in fact I suspect
that to comprehend the code it can be worse than using function
keyword since an explicit and long keyword gives a useful reference
indeed.

The bottom line: "=>" allows to create incomprehensible but nicely
looking code yet for simpler down-to earth cases its advantages are
minor if any.

Regards, Igor



More information about the Es4-discuss mailing list