In yesterday’s email, I failed to include the example included in the spec, which doesn’t make sense to include otherwise. I’ve updated the web version of the email in case you’re super curious to see what I left out.
We’ve already covered these details, but they’re logically mentioned again in the section about function calls, so we’ll cover them here:
Calls
…
A method call
x.m()
is valid if the method set of (the type of)x
containsm
and the argument list can be assigned to the parameter list ofm
. Ifx
is addressable and&x
’s method set containsm
,x.m()
is shorthand for(&x).m()
:var p Point p.Scale(3.5)
There is no distinct method type and there are no method literals.
The main point of interest is this last point: There are no method literals. You can express a function literal:
func() {}
But there’s no way to express a method literal. This implies that you cannot create methods within functions, or create method closures, or add arbitrary methods at runtime, etc.
Quotes from The Go Programming Language Specification Version of August 2, 2023