On Wed, Feb 1, 2023 at 11:22 AM Chris Burkert
wrote:
> Looking into the spec:
>
> https://go.dev/ref/spec#Return_statements
> ReturnStmt = "return" [ ExpressionList ] .
> ExpressionList = Expression { "," Expression } .
> ... no () here
>
> https://go.dev/ref/spec#Function_types
> FunctionType
Looking into the spec:
https://go.dev/ref/spec#Return_statements
ReturnStmt = "return" [ ExpressionList ] .
ExpressionList = Expression { "," Expression } .
... no () here
https://go.dev/ref/spec#Function_types
FunctionType = "func" Signature .
Signature = Parameters [ Result ] .
Result
This is really helpful! Thank you!
At first I assumed that it was down to 'go fmt' letting you be fairly loose
with your syntax and that you could omit parentheses where the meaning
wouldn't be ambiguous. But on closer examination, there must be something
else going on because 'return a, b' wo
Good point, didn't think of that
On Wed, Feb 1, 2023, 15:30 p...@morth.org wrote:
> It would actually be ambiguous in the very place they're required.
>
> Consider this not completely unreasonable example:
> https://go.dev/play/p/OL0uOnPZXju
>
> Also, with generics it could be ambiguous in type
It would actually be ambiguous in the very place they're required.
Consider this not completely unreasonable example:
https://go.dev/play/p/OL0uOnPZXju
Also, with generics it could be ambiguous in type parameters.
To summarize, parentheses are needed around the return types because
otherwise an
I'm not sure there really is a "reason", per se. The language could just as
well have been designed not to require parentheses around the return types
(at least I see no parsing ambiguity with that, though there might be) or
designed to require parentheses in the return statement. It probably just
Hey all, I figured it was time to move to a "modern" language and I thought
I'd give go a try. So far, I'm really enjoying it. I'm just getting started
and I had a question about parentheses. Though, I guess it's really about
how go parses lines of code and what counts as a delimiter.
Anyway, i