[erlang-questions] iterators in Erlang

James Hague james.hague@REDACTED
Wed Oct 25 19:10:31 CEST 2006


On 10/25/06, Robert Raschke <rrerlang@REDACTED> wrote:
>
> I'm not up to date with Python, but what kinds of control structures
> does it provide enumerate values from a generator?  Is it the OO
> iterator concept of having to explicitly call some kind of next()
> method?  In that case there appears not to be any obvious advantage
> over "just" writing processes in Erlang to generate values and
> communicating with messages.

"for" in Python works automatically with generators:

for line in file:
   print line

"file" in this case is an interator that returns each line in a file.

This also works with list comprehensions:

[i for i in xrange(10)*2]

James



More information about the erlang-questions mailing list