Concise functions, Nonexistent lambdas, Explicit tail calls

Jon Zeppieri jaz at bu.edu
Tue Dec 9 17:54:45 PST 2008


On Tue, Dec 9, 2008 at 7:25 PM, Brendan Eich <brendan at mozilla.com> wrote:
>
> The relations are not simple. But I have to say that the lambda-coded for
> loop examples:
> https://mail.mozilla.org/pipermail/es-discuss/2008-October/007822.html
> were not what I would call clear specifications -- at least not to the
> audience of JS implementors working in C++ or a similar language, and not
> experienced lambda-coders.

Those were encodings of a for loop that binds the variables in its
initialization expression on every iteration.  It's not surprising
that it would be complicated to take a user's "i++" and, essentially,
turn it into "rebind i with i + 1."  It's also not polite.  Desugaring
a normal 'for' loop is straightforward. (Well, getting the completion
value right introduces a bit of oddness, but not much.)

for (initExpr; condExpr, updateExpr) body; ==>

{
  initExpr;

  let $loop = lambda($v) {
    if (condExpr) {
      let $v0 = (lambda() { body; })();   // get the completion value of body
      updateExpr;
      $loop($v0);
    } else {
      $v;
    }
  };

  $loop(<emptyCompletionValue>);
}


More information about the Es-discuss mailing list