package main
import "fmt"
func main() {
// make an Add2 function, give it a name p2, and call it:
p2 := Add2(1)
fmt.Printf("Call Add2 for 3 gives: %v\n", p2(3))
// make a special Adder function, a gets value 3:
TwoAdder := Adder(2)
fmt.Printf("The result is: %v\n", TwoAdder(3))
}
func Add2(a int) func(b int) int {
return func(b int) int {
return b + a
}
}
func Adder(a int) func(b int) int {
return func(b int) int {
return a + b
}
}
有疑问加站长微信联系(非本文作者)