Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update README.md #20

Merged
merged 1 commit into from
May 4, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -172,20 +172,21 @@ func scope() func() int{
}

func another_scope() func() int{
// won't compile because outer_var and foo not defined in this scope
outer_var = 444
return foo // foo() will return 2
return foo
}


// Closures: don't mutate outer vars, instead redefine them!
func outer() func() int, int{
func outer() (func() int, int) {
outer_var := 2
inner := func() int {
outer_var += 99 // attempt to mutate outer_var from outer scope
return outer_var // => 101 (but outer_var is a newly redefined
// variable visible only inside inner)
}
return foo, outer_var // => 101, 2 (outer_var is still 2, not mutated by foo!)
return inner, outer_var // => 101, 2 (outer_var is still 2, not mutated by foo!)
}
```

Expand Down