Re:More Gotchas of Defer in Go, Part II
by pcwalton on Thursday December 21, 2017 @08:09PM
(#15984471)
> If it was scope based there's nothing you could do to get func_defer behavior.
That's clearly false. You could set up a list to hold objects to be disposed (or, more generally, closures to execute) and defer a simple procedure that disposes of all objects in the list. This is in fact what the implementation of defer must do internally.
Re:More Gotchas of Defer in Go, Part II
by ovao on Friday December 22, 2017 @12:24AM
(#15985439)
I think by that he means it wouldn't be possible to get func_defer behavior in the example with a single keyword, or without some form of qualifier. The compiler wouldn't be able to differentiate the behavior.
That's clearly false. You could set up a list to hold objects to be disposed (or, more generally, closures to execute) and defer a simple procedure that disposes of all objects in the list. This is in fact what the implementation of defer must do internally.