>
> It looks only a very small part of expressions can be viewed as statements.


Why only a small fraction of expressions can be viewed as a statement?
I agree that only a fraction can be _usefully_ used as a statement, but all
are ok as statement.
The key is that when using an expression as a statement you're effectively
ignoring its value. This means you have to find the side effects of
evaluating the expression interesting enough (as in the Println example).
Expressions with no side effects, such as i+1 are clearly not useful and
compilers/linters will warn you about them.
And this difference (having side effects vs not having side effects cannot
be captured in a grammar), so you have to allow for all expressions as
statement.

On Sun, Jan 14, 2018 at 10:41 AM, <d...@veryhaha.com> wrote:

>
>
> On Sunday, January 14, 2018 at 10:14:21 AM UTC-5, Axel Wagner wrote:
>>
>> Why not? The linked Expression section (more specifically, the Expression
>> *rule*) defines the format of expressions. An expression statement
>> allows you to use any expression also as a statement; this is important,
>> because it means you can, e.g. write
>> fmt.Println("foobar")
>> as an expression (without needing an assignment or the like).
>>
>
> Ok, I think I get it.
> It looks only a very small part of expressions can be viewed as statements.
>
> Thanks.
>
>
>
>>
>> On Sun, Jan 14, 2018 at 4:07 PM, dg <di...@veryhaha.com> wrote:
>>
>>>  In this section, it shows
>>>
>>> ExpressionStmt = Expression <https://golang.org/ref/spec#Expression> .
>>>
>>> However, it looks the content in this section has nothing related to the
>>> linked Expression section.
>>>
>>>
>>> --
>>> You received this message because you are subscribed to the Google
>>> Groups "golang-nuts" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to golang-nuts...@googlegroups.com.
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>> --
> You received this message because you are subscribed to the Google Groups
> "golang-nuts" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to golang-nuts+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to