Complete TODO for coalesced function parameters.
This commit is contained in:
parent
6494e4478b
commit
abcd36fec0
@ -15,12 +15,21 @@ func plus(a int, b int) int {
|
|||||||
return a + b
|
return a + b
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// When you have multiple consecutive parameters of
|
||||||
|
// the same type, you may omit the type name for the
|
||||||
|
// like-typed parameters up to the final parameter that
|
||||||
|
// declares the type.
|
||||||
|
func plusPlus(a, b, c int) int {
|
||||||
|
return a + b + c
|
||||||
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
|
||||||
// Call a function just as you'd expect, with
|
// Call a function just as you'd expect, with
|
||||||
// `name(args)`.
|
// `name(args)`.
|
||||||
res := plus(1, 2)
|
res := plus(1, 2)
|
||||||
fmt.Println("1+2 =", res)
|
fmt.Println("1+2 =", res)
|
||||||
}
|
|
||||||
|
|
||||||
// todo: coalesced parameter types
|
res = plusPlus(1, 2, 3)
|
||||||
|
fmt.Println("1+2+3 =", res)
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
$ go run functions.go
|
$ go run functions.go
|
||||||
1+2 = 3
|
1+2 = 3
|
||||||
|
1+2+3 = 6
|
||||||
|
|
||||||
# There are several other features to Go functions. One is
|
# There are several other features to Go functions. One is
|
||||||
# multiple return values, which we'll look at next.
|
# multiple return values, which we'll look at next.
|
||||||
|
Loading…
x
Reference in New Issue
Block a user