tc39 / proposal-do-expressions

Proposal for `do` expressions
MIT License
1.11k stars 14 forks source link

`DO` should eliminate all statements, convert all statements to expressions #36

Open kghost opened 5 years ago

kghost commented 5 years ago

Movation

There is already some language only support expressions, and no statements at all, like scala.

I have seen that one purpose do does is that convert statements to expressions, but why can't we push it further, that let it eliminate ALL statements

FOR statement

collect all loop result will cause performance issue when running legacy codes

do { for (const x of y) z(x) }  -> y.foreach(x => z(x)) : undefined

so maybe another do is needed:

do { for (const x of y) do { z(x) } }  -> y.map(x => z(x)) : generator(typeof z(x))

TRY statement

do { try x catch(e) y finally z }  -> { try return x catch(e) return y finally z }

return finally if inside do:

do { try x finally do z }  -> try x finally return z }

More statements ...

Looking for your help !

Conclusion

We can eliminate all statements, convert all of statements to expressions to make our javascript life better