No code block without introductory keyword (was: Re: Boolean shortcuts)
If we force a formal block introduction, there will be some problems with codes like this one :
var foo = function ( ) { { let x = 42; console.log( x ); } { let x = 24; console.log( x ); } }
If someone use ES6 features while the spec isn't done yet, he takes the risk of having his code breaking as the specification evolve.
In this case, he would have to rewrite his code as
var foo = function() {
eval {
let x = 42;
console.log( x );
}
eval {
let x = 24;
console.log( x );
}
}
François
I am sorry that I am so dense in my communication, I meant not only "no code block without formal introduction", but also adding a keyword to the repertoire that, in those rare cases of free code block (they are not really that common), introduces a free code block. The rule of NCBWFI makes the code really formally clearer. You see in François's example that the change is not big (I would personally like "local" more than "eval", somehow the old associations from the university sprung up from SML/NJ course where local and let were coupled, so it seemed like good choice, but "local" cannot be a keyword since it is surely used in lots of places as a variable name).
Herby
-----Pôvodná správa---
Hello,
Brandon Eich recently mentioned do expression, so I looked them up (strawman:do_expressions). It seems they can have good use here (though it is by accident). It would verily be possible to adopt "no { ambiguity" rule by mandating "all {....} uses must have formal introductory context, including 'no context' which implies {...} is a data-production use of {...}", in which case do expression would be ideal to include a free code block anywhere it can be needed. No need to invent new mechanism / keyword.
Herby
-----Pôvodná správa---
what you proposed seems like a pretty good idea (at least imho). All other uses of {...} as code block have a introductory keyword / control structure (if, else, while, do, function), and even the newcomer {...} uses like module and class are preceded by one. If (maybe in "strict ES6+" only) there was the general rule of "no code block without formal introduction", it could make parsing much more quirk-free (and it would be clearly define that {...} without introduction is always object literal (or, more broadly, data-producing {...} (declarative curlie)) in contrast to imperative curlie that contains some form of action to perform).
Herby
-----Pôvodná správa---