Created
March 23, 2014 15:38
-
-
Save kyanny/9724794 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
func adder (n int) func() int { | |
sum := 0 | |
return func () int { | |
sum += n | |
return sum | |
} | |
} | |
var sum2 int | |
func adder2 (n int) func () int { | |
sum2 = 0 | |
return func () int { | |
sum2 += n | |
return sum2 | |
} | |
} | |
func main() { | |
fmt.Println("Hello, playground") | |
add1 := adder(1) | |
add2 := adder(2) | |
add3 := adder2(3) | |
for i := 0; i < 10; i++ { | |
fmt.Println(add1(), add2(), add3()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment