revive let blocks

classic Classic list List threaded Threaded
26 messages Options
12
Reply | Threaded
Open this post in threaded view
|

Re: revive let blocks

Matthew Robb

I feel like this would just get confused with object destructuring.

On Jun 25, 2015 5:17 PM, "Herby Vojčík" <[hidden email]> wrote:
Hello!

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.

Herby

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
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: revive let blocks

Brendan Eich-2
Matthew Robb wrote:
>
> I feel like this would just get confused with object destructuring.
>

Not just confused -- it is fatally ambiguous.

I think do expressions are "go" for ES7 but they need re-championing,
and implementation. I'll stir the pot.

/be
_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: revive let blocks

Matthew Robb

On Thu, Jun 25, 2015 at 6:20 PM, Brendan Eich <[hidden email]> wrote:
I think do expressions are "go" for ES7 but they need re-championing, and implementation. I'll stir the pot.

​Might this include something like the following form?: ` do(let x = 1) {} `​. Seems like that might satisfy Kyle's original request.



- Matthew Robb

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: revive let blocks

Kevin Smith
In reply to this post by Brendan Eich-2
I think do expressions are "go" for ES7 but they need re-championing,
and implementation. I'll stir the pot.

I think Andreas was interested at some point?

I've long been interested in the possibility of a "do async" as well. : )

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: revive let blocks

Andreas Rossberg-4
On 26 June 2015 at 04:08, Kevin Smith <[hidden email]> wrote:
I think do expressions are "go" for ES7 but they need re-championing,
and implementation. I'll stir the pot.

I think Andreas was interested at some point?

Yes, I'm planning to prepare a proper spec for the September meeting. I'm also hoping we get a prototype impl in V8 some time later this year, although I'd rather not promise anything.

/Andreas


_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
Reply | Threaded
Open this post in threaded view
|

Re: revive let blocks

Kevin Smith
Yes, I'm planning to prepare a proper spec for the September meeting. I'm also hoping we get a prototype impl in V8 some time later this year, although I'd rather not promise anything.

Cool - looking forward to it!

_______________________________________________
es-discuss mailing list
[hidden email]
https://mail.mozilla.org/listinfo/es-discuss
12