2 ms·
In a similar vein, closures are not necessary, since they can always be emulated by a global function with a data object to bundle captured state - which is sti
by int_19h 4y ago
In a similar vein, closures are not necessary, since they can always be emulated by a global function with a data object to bundle captured state - which is still the usual way to do it in C, for example. But this sort of thing gets real awkward real fast if you do it a lot. Same thing with explicit iterators vs generators.
- lmm 4y ago> they can always be emulated by a global function with a data object to bundle captured state Only if you already have the infrastructure in place to pass that captured state through to where it's needed. For a C example, you can't (safely) use an "emulated closure" with qsort (e.g. if you want to write a function that takes a list and an integer, and sorts the list modulo that integer), because you have no way to pass the data object through.