Skip to content

Instantly share code, notes, and snippets.

@ntakk
Created August 27, 2012 06:49
Show Gist options
  • Select an option

  • Save ntakk/3486323 to your computer and use it in GitHub Desktop.

Select an option

Save ntakk/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
@ntakk
Copy link
Copy Markdown
Author

ntakk commented Aug 27, 2012

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

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