Implicit return syntax error

Alex Blewitt alex.blewitt at gmail.com
Wed Dec 16 00:50:32 PST 2009


On Dec 16, 2009, at 06:15, Mike Swingler wrote:

> It may be terser by a few characters, but it's an impedance mismatch
> with the rest of the language as it exists today, which reduces
> understandability.

Understandability is always such a subjective measure that it probably  
doesn't behove to pay too much attention, particularly for things that  
involve new syntax in any case.

Note that 'return' is not always needed; for example:

int a = -b + sqrt(pow(b,2)-4*a*c)/(2*a);

has no return statement in there - it's just the result of an  
expression. On the other hand, I don't think it matters (in the case  
of an expression) whether the return is needed or not; it might well  
be the case that it's an optional item. That would permit the more  
verbose format for those that are more comfortable with it whilst  
allowing a reduced form for those that are more comfortable with the  
same. In addition, other languages have this kind of construct e.g.  
Python:

 >>> sq = lambda x: x**2
 >>> sq(4)
16

> Later, it may make sense to propose implicit
> return statements for the language in all contexts, and not just a  
> one-
> off special case for lambdas.

That might also be interesting (but out of scope here). Of course, an  
optional 'return' allows that as well.

As well as block expressions (i.e. those that return the last value  
implicitly), would we have non-block expressions?

fortyTwo = #() 42;

alex


More information about the lambda-dev mailing list