One year of Go

retard re at tard.com.invalid
Sat Nov 13 06:21:04 PST 2010


Sat, 13 Nov 2010 08:27:04 -0500, bearophile wrote:

> retard:
> 
>> Any links to relevant research?
> 
> If your JavaScript function ends with this, what kind of errors or
> return value does it generate?
> 
> return
>     2 + 2;
> 
> Found in this thread:
> http://stackoverflow.com/questions/1995113/strangest-language-feature

You also mentioned Scala. In Scala you need to write the return type to 
the function signature when explicitly using 'return'. The only case 
where this can fail in Scala is when the return type is Unit. Would be 
strange to try to return 2+2 in that case.

Andrei also mentioned this:

> method fun() { 42 }
>   to return an integer, and
> method fun() { 42; }
>   to return void.

in Scala both

> def fun = { 42; }
> def fun = { 42 }

return the same function.

The only cases in Scala when the expression fails is when you write a 
multiline expression and forget to surround the expression with braces or 
parentheses.


More information about the Digitalmars-d mailing list