Basic Lambdas and Explicit Tail Calls Repackaged

Michael Day mikeday at yeslogic.com
Mon Dec 8 00:27:21 PST 2008


Hi Brendan,

> There's a lesser goal I didn't list: make function syntax thinner. 
> 'function' is eight whole letters, plus four chars of parens and braces, 
> plus 'return'. Wherefore expression closures in JS1.8 -- they save the 
> braces and 'return' overhead. But to fix expression closures to be 
> bottom-up unambiguous we would require at least parens around the 
> body-expression.

Allow "fun" as a shorthand for "function" similar to "var" being a 
shorthand for "variable", and you can add back the parentheses and still 
make a saving:

     fun(n) (n + 1)

Actually I think it's a great idea to allow function bodies to be 
expressions when wrapped in parentheses and blocks when wrapped in 
braces. It's obvious and consistent with other syntax.

> More concise function syntax is not a goal solely, or even exclusively, 
> to support user-defined control abstractions. It's a good in its own 
> right unless you consider every use of a function expression in JS today 
> to be a control abstraction in the Smalltalk block sense (I do not).

Concise syntax is good. When I look at these:

     function ident(args) { body ; return }
     function ident(args) ( expression )

the only way it can be made more concise is by shrinking the "function" 
keyword. The ident is already optional, as are the args, the return is 
no burden given that the body is already there, and functions with no 
body can use expression form instead.

I don't think that you can get much more concise than this without 
fundamentally changing the nature of JavaScript and its syntax:

     fun(x) {x(1)}
     fun(x) (x + 1)

Adding "fun" to millions of scripts all over the world could also have a 
powerful subliminal effect on JavaScript programmers, as compared with 
the way that the "die" command ushered in the extinction of Perl :)

Cheers,

Michael

-- 
Print XML with Prince!
http://www.princexml.com


More information about the Es-discuss mailing list