Download - Paren free
![Page 1: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/1.jpg)
Paren-freeBrendan Eich
Saturday, June 11, 2011
![Page 2: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/2.jpg)
Motivation
Saturday, June 11, 2011
![Page 3: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/3.jpg)
History
Saturday, June 11, 2011
![Page 4: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/4.jpg)
History
• JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity.
Saturday, June 11, 2011
![Page 5: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/5.jpg)
History
• JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity.
• Many JS style guides favor mandatory bracing of if consequents and other sub-statement bodies, in order to avoid dangling else bugs.
Saturday, June 11, 2011
![Page 6: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/6.jpg)
History
• JS derives from Java from C++ from C (via early C and B), from BCPL. BCPL had paren-free if, etc., heads disambiguated via the do reserved word to separate an expression consequent, avoiding ambiguity.
• Many JS style guides favor mandatory bracing of if consequents and other sub-statement bodies, in order to avoid dangling else bugs.
• By comparison to nearby programming languages, JS syntax is “shifty” to write and noisy to read. Can we do better?
Saturday, June 11, 2011
![Page 7: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/7.jpg)
Examplesif year > 2010 { syntax++}
for let i of iter { // i is fresh on each iteration frob(i)}
while lo <= hi { let mid = (lo + hi) / 2
// binary search body goes here}
... return [i * i for i in range(n)] // array comprehension
Saturday, June 11, 2011
![Page 8: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/8.jpg)
Examples, cont.• Must support:
if x < y {
} else if x < z {
} else if x < w {
} else {
}
• but not mandate:
if x < y {
} else {
if x < z {
} else {
if x < w {
} else {
} } }
Saturday, June 11, 2011
![Page 9: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/9.jpg)
Syntax
• IfStatement :
if Expression SubStatement else SubStatement if Expression SubStatement if ( Expression ) OtherStatement else Statement if ( Expression ) OtherStatement
• etc. for while, do-while, for, switch, catch
• SubStatement :
Block KeywordStatement
Saturday, June 11, 2011
![Page 10: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/10.jpg)
Syntax, cont.• KeywordStatement :
IfStatement IterationStatement ContinueStatement BreakStatement ReturnStatement SwitchStatement ThrowStatement TryStatement DebuggerStatement
• Statement :
Block KeywordStatement OtherStatement
• OtherStatement :
EmptyStatement ExpressionStatement LabelledStatement VariableStatement
Saturday, June 11, 2011
![Page 11: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/11.jpg)
Compatibility
Saturday, June 11, 2011
![Page 12: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/12.jpg)
Compatibility
• if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized.
Saturday, June 11, 2011
![Page 13: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/13.jpg)
Compatibility
• if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized.
• try, catch, finally must be braced as in ES3 and ES5.
Saturday, June 11, 2011
![Page 14: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/14.jpg)
Compatibility
• if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized.
• try, catch, finally must be braced as in ES3 and ES5.
• catch heads may be parenthesized or unparenthesized.
Saturday, June 11, 2011
![Page 15: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/15.jpg)
Compatibility
• if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized.
• try, catch, finally must be braced as in ES3 and ES5.
• catch heads may be parenthesized or unparenthesized.
• for heads may be parenthesized or unparenthesized.
Saturday, June 11, 2011
![Page 16: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/16.jpg)
Compatibility
• if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized.
• try, catch, finally must be braced as in ES3 and ES5.
• catch heads may be parenthesized or unparenthesized.
• for heads may be parenthesized or unparenthesized.
• for-in/of heads may be parenthesized or unparenthesized.
Saturday, June 11, 2011
![Page 17: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/17.jpg)
Compatibility
• if, while, do-while, and switch statements, where the head syntax is Expression, which may be over-parenthesized.
• try, catch, finally must be braced as in ES3 and ES5.
• catch heads may be parenthesized or unparenthesized.
• for heads may be parenthesized or unparenthesized.
• for-in/of heads may be parenthesized or unparenthesized.
• for-of loop, comprehension, and generator expression new semantics (next slide).
Saturday, June 11, 2011
![Page 18: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/18.jpg)
for-in & for-of
Saturday, June 11, 2011
![Page 19: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/19.jpg)
for-in & for-of• for k in o iterates over keys not values for all objects o.
Saturday, June 11, 2011
![Page 20: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/20.jpg)
for-in & for-of• for k in o iterates over keys not values for all objects o.
• for k of {p:1, q:2} iterates over 1, 2.
Saturday, June 11, 2011
![Page 21: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/21.jpg)
for-in & for-of• for k in o iterates over keys not values for all objects o.
• for k of {p:1, q:2} iterates over 1, 2.
• for v of [3, 4, 5] iterates over 3, 4, 5.
Saturday, June 11, 2011
![Page 22: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/22.jpg)
for-in & for-of• for k in o iterates over keys not values for all objects o.
• for k of {p:1, q:2} iterates over 1, 2.
• for v of [3, 4, 5] iterates over 3, 4, 5.
• for k of keys(o) iterates over keys in o.
Saturday, June 11, 2011
![Page 23: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/23.jpg)
for-in & for-of• for k in o iterates over keys not values for all objects o.
• for k of {p:1, q:2} iterates over 1, 2.
• for v of [3, 4, 5] iterates over 3, 4, 5.
• for k of keys(o) iterates over keys in o.
• for v of values(o) iterates over values in o.
Saturday, June 11, 2011
![Page 24: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/24.jpg)
for-in & for-of• for k in o iterates over keys not values for all objects o.
• for k of {p:1, q:2} iterates over 1, 2.
• for v of [3, 4, 5] iterates over 3, 4, 5.
• for k of keys(o) iterates over keys in o.
• for v of values(o) iterates over values in o.
• for [k, v] of items(o) iterates over key/value pairs.
Saturday, June 11, 2011
![Page 25: Paren free](https://reader033.vdocuments.mx/reader033/viewer/2022052820/54b7793a4a7959e20d8b45ae/html5/thumbnails/25.jpg)
for-in & for-of• for k in o iterates over keys not values for all objects o.
• for k of {p:1, q:2} iterates over 1, 2.
• for v of [3, 4, 5] iterates over 3, 4, 5.
• for k of keys(o) iterates over keys in o.
• for v of values(o) iterates over values in o.
• for [k, v] of items(o) iterates over key/value pairs.
• for x of proxy iterates using the handler iterate trap.
(http://wiki.ecmascript.org/doku.php?id=harmony:iterators)
Saturday, June 11, 2011