FWIW, I definitely like this proposal more than any convoluted
var-scoping block proposal.
I just don't see the value of adding var-scoping blocks for the added
parser complexity, and problematic return/break/continue.
Even if the return/break/continue problem is solved, it shouldn't just
be for var-scoping blocks - it should be generalized to first-class
Ruby-esque block.
So if we ever want to add var-scoping blocks with proper
return/break/continue, consider Ruby-esque blocks. Something like:
function treePreorder(tree, func) {
func(tree.value);
if (tree.left)
treePreorder(tree.left, func);
if (tree.right)
treePreorder(tree.right, func);
}
function treeContains(tree, x) {
treePreorder(some_tree, block(val) {
if (val == x) return true;
});
return false;
}
Though, I'd imagine implementing this would also be difficult (at the
very least, non-trivial), and this example can be easily replaced with
one that used exceptions/try/catch anyway.
-Yuh-Ruey
Igor Bukanov wrote:
> 2008/7/28 Ingvar von Schoultz <[EMAIL PROTECTED]>:
> >
> > {{ }} is just the same as a scoping function used on ES3:
> >
> > (function() { code })()
>
> As Lars Hansen has pointed out any proposal for a shorthand for
> (function() { code })() has to deal with break/continue/return inside
> the code. This is the the reason if anything I would prefer in ES3.1
> just shorthands for function definitions like
>
> function() expr - equivalent to function () { return expr; }. This is
> already in ES4 and is implemented by at least on implementation
> (SpiderMonkey).
>
> or
>
> function optional_name { code } - equivalent to function
> optional_name() { code } - a hypothetical shortcut that would allow to
> write a pseudo-blocks like
>
> function {
> }();
>
> with clear emphasis that this is a lambda with usual rules for
> break/continue/return.
>
> Regards, Igor
> _______________________________________________
> Es3.x-discuss mailing list
> [EMAIL PROTECTED]
> https://mail.mozilla.org/listinfo/es3.x-discuss
>
>
_______________________________________________
Es4-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es4-discuss