4 ms·
One can sort of get a non reference capture, by passing the same name as a argument; but yes it would be nice if one could somehow say capture by value. fo
by dfawcus 2y ago
One can sort of get a non reference capture, by passing the same name as a argument; but yes it would be nice if one could somehow say capture by value.
foo := 1
closure := func(foo int) func() int { return func() int { return foo += 1 } }(foo)
x := closure() // 2, w/o altering outer foo
If not something like the above, I'm not sure what you're trying to express. Possibly what 'foldr' suggested, or that with mine such that one passes in the initial closure function as a argument?