package main
import (
"fmt"
)
func main() {
a, b := test(1,2)
fmt.Println("random text", a, b)
}
func test(int,int) (int,int) {
return 3, 4
}
This would work. You can use only single return value functions directly in a print statement. There are other complicated ways to accommodate that, but for now this is the simple way.
I’ve never given print statements with a function alone (Always will have some string message) . Used to doing it the way I mentioned.
You are right. I tried with other return types as well. Same behavior. There must be some reason behind it. Lets see what the others have to say. Might be something obvious.
As a special case, if the return values of a function or method g are equal in number and individually assignable to the parameters of another function or method f, then the call f(g(parameters_of_g)) will invoke f after binding the return values of g to the parameters of f in order. The call of f must contain no parameters other than the call of g, and g must have at least one return value. If f has a final … parameter, it is assigned the return values of g that remain after assignment of regular parameters.
func Split(s string, pos int) (string, string) {
return s[0:pos], s[pos:]
}
func Join(s, t string) string {
return s + t
}
if Join(Split(value, len(value)/2)) != value {
log.Panic("test fails")
}
So calling a function given one function with multiple returns as only parameter is allowed.