On 1 October 2012 15:10, Dumitru Ungureanu wrote:
So since function in Go are types,
Go functions are not types. They /have/ types, just like all
the other values in Go.
this declares a type:
x := os.Getgid
No, it declares the variable x. It has whatever type os.Getgid has,
which (consults godoc) is func()int.
What happens when I attach parenthesis to the type?
That's not what you're doing (since x isn't a type). You're
writing a function call of whatever function x currently is
(viz, os.Getgid) and no arguments. The result will be that
os.Getgid is called (and its result is dropped on the floor.)
I mean, I know what happens (now), it's a function call, not a type
declaration, but what's the mechanism?
The declaration copies the value of the function os.Getgid
into x. "The value of the function" will be something very
like a pointer to its code, or a structure that contains a pointer
to its code. The call calls whatever function is pointed to.
Since there are no closures involved, that's pretty much
what happens in C or C++ pointer-to-functions, or in
Scheme functions or Pop11 procedures: No New Magic.
Chris "allusive" Dollin