Skip to content

Instantly share code, notes, and snippets.

@takungsk
Created August 27, 2012 06:49
Show Gist options
  • Save takungsk/3486323 to your computer and use it in GitHub Desktop.
Save takungsk/3486323 to your computer and use it in GitHub Desktop.
クロージャの動作確認
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
@takungsk
Copy link
Author

クロージャの中で match 使うにはどうすりゃいいんだ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment