Thanks! :)
On Sunday, February 18, 2018 at 3:11:45 PM UTC-5, Krzysztof Kowalczyk wrote:
>
> I'm far from the expert on the spec but the behavior seems to follow the
> rules.
>
> https://golang.org/ref/spec#Arithmetic_operators
>
> "Arithmetic operators apply to numeric values and yield a result o
I'm far from the expert on the spec but the behavior seems to follow the
rules.
https://golang.org/ref/spec#Arithmetic_operators
"Arithmetic operators apply to numeric values and yield a result of the
same type as the first operand."
myInt + myInt returns myInt because it's the type of first o
Thanks. Why is the plus operator defined on myInt? Or if it simply treats
a myInt as an int, why isn't the result an int?
Sorry if this is a stupid question; I think either there is something
deeper to this or else the arithmetic operators just have a special
processing for this case.
On Sun
On Sun, Feb 18, 2018 at 8:06 PM Bill Wood wrote:
> I thought that the plus operator would return an int, not a myInt.
expr1 + expr2 works iff types of expr1 and expr2 are the same and the
result has the same type as both of the operands. Analogically for the
subtraction, multiplication and divis
Thanks, my question is about this line in your expanded plus function:
res := aInt + bInt // type: myInt
It's not clear to me why *aInt + bInt* results in a type myInt. I thought
that the plus operator would return an int, not a myInt.
On Sunday, February 18, 2018 at 3:00:00 AM UTC-5, Krzyszt
2 things:
1. plus() returns interface{}.
"%T" prints underlying dynamic type of interface{} value, but static type
of returned value of plus is interface{}
You can assign any type to interface{} without a cast by definition (see
e.g. https://www.programming-books.io/essential/go/a-90100072-em