arrow syntax unnecessary and the idea that "function" is too long

Claus Reinke claus.reinke at
Sat May 7 14:39:13 PDT 2011

> Consider this: w = (x)->y || z
> That code is not obvious at all.  Which of these would it be?
> 1: w = function (x) { return y } || z
> 2: w = function (x) { return y || z }
> It seems to me that there must be some sort of delineation 
> around the function start and end.  

But such delineation does not have to lead to required syntax
in the function construct. Such required delineations were not
part of lambda-calculus originally **, they arose out of 
implementation limitations that can be overcome.

I know that takes some getting used to (been there myself*), 
but there is an established standard, both in publications on
programming language theory, and in some real languages: 

    function bodies extend as far as possible **

So your examples would be

1: w = (function (x) return y) || z
2: w = (function (x) return y || z)

If the right-hand side itself is delimited, 2 could also be written

2': w = function (x) return y || z

The idea is that we can always "shorten" an unbounded function 
by enclosing it with existing grouping constructs, but we cannot 
"lengthen" a pre-delineated function in any way, nor can we get
rid of the delineating parens and braces if they are required in
the grammar. Combining non-delineated functions with grouping
constructs gives us a modular and unambiguous solution.

Another issue is that of blocks in function bodies. It would be
nice if blocks were values - then procedures would just be
block-returning functions, and all functions would just return
values, separating the function construct from the details of
block execution. Not sure whether such niceties would work 
in javascript, though:-)


* I used to write my lambda-calculus terms fully parenthesized,
    because the functional languages I knew (before Haskell) 
    required that style. Many programming language theory
    folks found that style difficult to read, because they had 
    grown up with the extends-as-far-as-possible convention. 

** Church,  Barendregt, .., they all define lambda-terms as

    term := x | (\x term) | (term term)

    with additional conventions to drop parentheses where
    possible, such as

    (A B C D) instead of (((A B) C) D)
    (\x y z.M) instead of (\x (\y (\z M)))


More information about the es-discuss mailing list