[erlang-questions] iterators in Erlang

James Hague james.hague@REDACTED
Wed Oct 25 15:51:03 CEST 2006


I've recently been brushing up on my Python, because I'm teaching a
class using it.  What's surprising to me is how much modern Python
relies on iterators (an "iterator" being an object that returns one
value at a time in a sequence).  Where lists:seq(1,100000) returns a
large list in erlang, xrange(1,100000+1) in Python generates one value
at a time.  Then you can sum these values with sum(xrange(1,100000+1))
and there's still no intermediate list.

Even more interesting is that iterators have evolved into generators,
which are a poor man's processes).  People are twisting generators to
get cooperative multitasking.

What jumps out at me is how natural this stuff is to do in Erlang, and
yet the iterator/generator style isn't an inherent part of the Erlang
libraries.  I'm not sure if it really *should* be, of course, but I
was curious why Erlang never went down this path.

James



More information about the erlang-questions mailing list