Iterators and Ranges: Comparing C++ to D to Rust
Araq
rumpf_a at web.de
Tue Jun 15 07:22:24 UTC 2021
On Monday, 14 June 2021 at 23:08:40 UTC, Ola Fosheim Grøstad
wrote:
> On Monday, 14 June 2021 at 22:56:29 UTC, IGotD- wrote:
>> How do we classify the iterators of Nim?
>>
>> https://nim-lang.org/docs/tut1.html#iterators
>>
>> It looks similar to Python and Rust. Also notice how it can
>> use yield like a coroutine.
>
> Yes, but the page says that they have to be inlined and used in
> for-loops only? But if they are made more general then they
> would be generator coroutines like Python and C++.
There is also a variant called "closure" iterators which is Nim's
foundation for async programming. Nim's inline iterators don't
compose particularly well, but they get the job done and there
are all sorts of workarounds and 3rd party packages. We couldn't
copy C++ or D's designs because they are fundamentally unsafe
(iterator invalidation is complex and expensive). Rust can do it
easily thanks to its borrow checker. We're slowly catching up
with our support for "view types".
More information about the Digitalmars-d
mailing list