In this program: https://play.golang.org/p/AKrvuxF0wMK
is (s secretAgent).
Is the “s” here anywhere else in the program? What is the significance of “s”?
Are ther any returns in this program? And if so, what are they?
Oh gosh, I see “s” now, here: s.first, s.last
Anyone have a definition of “receiver”?
Also, a definition of "return?
I found this: Return statements
A “return” statement in a function F
terminates the execution of F
, and optionally provides one or more result values. Any functions deferred by F
are executed before F
returns to its caller. (Language Specification)
Is this what he’s referring to? Can anyone elaborate?
I can’t find “receiver”.
Methods are functions bound to a struct. The receiver is a parenthetical spec of the struct instance name so it can be used inside the function. So methods have receivers; pure functions do not. More at the link below.
A return statement is how a function or method returns any values to the caller. If you are asking about the “defer” bit, then lookup the defer in the language spec for details.
Thank-you
I studied your information carefully and saved the definitions to a file.
Do you see the return
keyword anywhere? Okay, neither do I, so it seems there are none.
Hi
A bound function can return values but yours doesn’t. It just prints some text. It works in the same way as regular functions
func double(x int) int {
return x * 2
}
The int after the ) tells the computer this function will return an int. And the return statement later will do this. On the other hand would a function which only printed some text maybe not return something and after the ) would there be nothing.
func printDouble(x int) {
fmt.Println(x * 2)
}
Do you see the return
keyword anywhere? Okay, neither do I, so it seems there are none.
Okay, so apparently from you said, the return
keyword must be present fir there to be a return.
Interesting. Thanks!
This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.