3 ms·
Indeed, the latter problem is the same as implicit traits. For the former, you can absolutely do it without having object-orientation or anything like that. Si
by jakobnissen 5y ago
Indeed, the latter problem is the same as implicit traits.
For the former, you can absolutely do it without having object-orientation or anything like that. Simply lower the iterator protocol to
```
itr = iterator(x)
while (i = next(itr)) !== nothing
# stuff
end
```
Then `itr` can be mutable, even when `x` isn't. This is what most modern languages does, and it solves all the problems I mentioned, since the state is stored in the mutable iterator, while at the same time, `x` can be unaffected.
Read more here: https://mikeinnes.github.io/2020/06/04/iterate.html https://mikeinnes.github.io/2020/06/04/iterate.html
- stellalo 5y agoWell, to be honest I still don’t understand the difference: they seem to me like two different styles of structuring the same kind of logic. In fact, the linked list example in the referenced article from Mike Innes I don’t find very convincing, stated as it is: I would like to see that example concretely, to understand how the current Julia protocol would fall short there (“leak”). Same for the `zip` example in the OP here: I’m not sure the Python `itr = iterate(xs)` kind of protocol makes it any simpler. But I’m on holiday and cannot try it out right now—I owe you one here :-)