Created
August 27, 2012 06:49
-
-
Save takungsk/3486323 to your computer and use it in GitHub Desktop.
クロージャの動作確認
This file contains hidden or 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
scala> def fo() = { | |
| var i=0 | |
| var s="init" | |
| () => { | |
| if (s == "init") { | |
| s = "add" | |
| i | |
| } else { | |
| i += 1 | |
| i | |
| } | |
| } | |
| } | |
fo: ()() => Int | |
scala> val func1 = fo() | |
func1: () => Int = <function0> | |
scala> println(func1()) | |
0 | |
scala> println(func1()) | |
1 | |
scala> println(func1()) | |
2 | |
scala> println(func1()) | |
3 | |
scala> println(func1()) | |
4 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
クロージャの中で match 使うにはどうすりゃいいんだ?