in view of the fact that more than one person misunderstood I meant, I declare that this article is not a question, this is a proposal. In fact, my article title has already explained everything. misunderstand people do not read the title?
I want rename the function:
func sum(x, y int) int { return x + y }
var myfunc = sum
// func myfunc(x, y int) int { return sum(x, y) }
it works but not good enough.
if we can change var
to func
:
func sum(x, y int) int { return x + y }
func myfunc = sum // or: func myfunc sum ?
don’t use type derivation:
func sum(x, y int) int { return x + y }
func myfunc(x, y int) int = sum // or: func myfunc(int,int) int = sum ?
// var myfunc func(int,int) int = sum
the right is a method:
type mytype struct{}
func (_ mytype) sum(x, y int) int { return x + y }
var myobject = new(mytype)
func myfunc = myobject.sum
// var myfunc = myobject.sum
if the left is a method, I don’t know what it should be.
The difference is that the var
syntax can assign multiple times, and func
can only assign once.