revive let blocks

Herby Vojčík herby at
Thu Jun 25 21:17:12 UTC 2015


Though this is a kind of syntax is probably macroable, interesting idea 
appeared in my mind regarding let blocks, so I would show it here, maybe 
it can actually be interesting for others as well.

The idea is to use existing let statement and extending it so one can 
include { ... code ... } block in place of last assignment. Hold on for 
a while: this form can merge with do-expressions by using 'let', not 
'do' as the keyword:

   let a = 4, b = 3; // normal let
   let { throw new Error("Throw in an expression"); } // let-expression
   let a = 4, b = 3, { a + b } // let-expression with own local lets

The third form is more or less the let-block from the PoV of reader, 
even if in fact is a new do-expression using let keyword with some 
let-assigment local to that block happening before.

I see a 'problem' that I can only distinguish if it is a let-statement 
or let-expression at the end of it, but afaict it does not pose any real 
gotchas for the compiler - it accumulates the assignment and at the 
either make them let-statement and use them for the rest of enclosing 
block or makes it let-expression and use them only locally.


Kyle Simpson wrote:
> Just to wrap this thread up, quoting myself from another thread:
> "In any case, I won't push my proposal anymore."
> ----
> But for posterity sake, wanted to make one last comment as to why the various suggestions for IIFE's and arrow expressions are inappropriate for the task: they change (hijack) the behavior of `return`, `break`, and `continue`. A standalone block like `{ let x = 2; .. }` or `let (x = 2) { .. }` can be placed anywhere, inside a function, loop, etc, and not hijack these types of statements.
> I'll be sticking with:
> ```js
> { let x = 42;
>      console.log("The meaning of JS: ", x);
> }
> ```
> Appreciate the various thoughtful responses.
> _______________________________________________
> es-discuss mailing list
> es-discuss at

More information about the es-discuss mailing list