Skip to content

Commit

Permalink
Merge pull request #20 from LordLandon/patch-1
Browse files Browse the repository at this point in the history
Update README.md
  • Loading branch information
codingsince1985 committed May 4, 2015
2 parents b1523ed + 833b6cc commit c1d4b1a
Showing 1 changed file with 4 additions and 3 deletions.
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

0 comments on commit c1d4b1a

Please sign in to comment.