A single form, func. The method is that form with a receiver me. or return propagates the error, instead of a comparison after each call.
x = ycopies the value.xis a variable or a field.x += yisx = x + y. The same family:-=,*=,/=,%=.
x.m(...)calls the methodmof the type ofx.mehas the typeTor*T, whereTis the type ofx. Ifmeis a*Tandxis a valueT, the call passes the address ofx. There is no&operator.
struct Compteur { n int }
func (me *Compteur) incrementer() {
me.n = me.n + 1
}
func main() int {
c := Compteur
c.incrementer()
c.incrementer()
return c.n
}
nom := Typedeclares the zero value ofType. A zerointis 0. A zeroboolisfalse. A zero struct has its fields to zero.
or returnpropagates an error.oris not a boolean operator.
func bon() error {
return nil
}
func main() int {
if bon() != nil {
return 1
}
return 0
}
A parameter may carry the name of a field: the field is written
me.nom.
Diagnostic. s'appelle me — the receiver must be named me.
Not in this version. Name overloading (several func f() with different signatures).