for-loops and declaration-like init expressions

2014-06-05 Thread Andreas Rossberg
C-style for-loops allow declarations as init statements, but only some of them. Yet, the others (function and class) are actually syntactically legal in that position as well, because they are simply parsed as expressions. Consider: let x = 0 for (let x = 1; ;) x // 1 for (const x = 1; ;)

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Mark S. Miller
Why not accept these as for-loop initializations, so that x actually has that function and that class as its initial value in the first iteration of the loop? To me, that's the least surprise. Since this is a position in which some declarations are accepted, anything there that looks like a

Re: for-loops and declaration-like init expressions

2014-06-05 Thread John Lenz
Would this still be legal, in this scheme? for ((function x(){}); ;) x // 0 for ((class x(){}); ;) x // 0 On Thu, Jun 5, 2014 at 7:58 AM, Andreas Rossberg rossb...@google.com wrote: C-style for-loops allow declarations as init statements, but only some of them. Yet, the others

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Will Ray
Mark, could you explain how the condition and iteration statements in the for loop interact with such an initialization? I agree that banning these seems like the clearer way to go. On Thu, Jun 5, 2014 at 10:17 AM, Mark S. Miller erig...@google.com wrote: Why not accept these as for-loop

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Mark S. Miller
Consider the function and class declarations in these positions to be equivalent to: for (let x = function(){}; ... and for (let x = class(){}; ... respectively. On Thu, Jun 5, 2014 at 8:32 AM, Will Ray wray...@gmail.com wrote: Mark, could you explain how the condition and

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Mark S. Miller
Hi John, for those it is unsurprising that they would be allowed, and that they would be taken as expressions rather than declarations. On Thu, Jun 5, 2014 at 8:23 AM, John Lenz concavel...@gmail.com wrote: Would this still be legal, in this scheme? for ((function x(){}); ;) x // 0 for

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Andreas Rossberg
On 5 June 2014 17:17, Mark S. Miller erig...@google.com wrote: Why not accept these as for-loop initializations, so that x actually has that function and that class as its initial value in the first iteration of the loop? To me, that's the least surprise. Since this is a position in which some

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Allen Wirfs-Brock
Over and beyond the breaking change WRT function, I really don’t see the value in such a restriction. There are many pointless or nonsensial things that can be written as expressions. In general, we don’t complicate the language to make such things illegal. Allen On Jun 5, 2014, at 7:58

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Mark S. Miller
Having this be legal as an expression makes the language more complex from the programmer's perspective than either * prohibiting this, by allowing only expression-statements as expressions here, or * accepting any declaration in this position. I would be surprised if the status quo were simpler

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Andreas Rossberg
On 5 June 2014 18:50, Allen Wirfs-Brock al...@wirfs-brock.com wrote: Over and beyond the breaking change WRT function, I really don’t see the value in such a restriction. There are many pointless or nonsensial things that can be written as expressions. In general, we don’t complicate the

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Brendan Eich
Allen Wirfs-Brock wrote: Over and beyond the breaking change WRT function, I bet a tasty donut that we cannot make this breaking change, so why should we fool around with anything similar for class? /be ___ es-discuss mailing list

Re: for-loops and declaration-like init expressions

2014-06-05 Thread Claude Pache
Le 5 juin 2014 à 16:58, Andreas Rossberg rossb...@google.com a écrit : The one caveat is that for function, that would actually be a breaking change, but is it likely to be a real world one? Here is a plausible example: for (function(){ /* ... */ }(); ; ) Today, the