[erlang-questions] Python Generators In Erlang and constant memory usage

Fred Hebert (MononcQc) mononcqc@REDACTED
Fri Mar 20 13:55:09 CET 2009


Yes, the lazy list implementation discussed there (and suggested by Jani
Launonen in this very thread) seem to be the best way to do it. Much better
than my way, given it would be subject to all kinds of weird behaviors when
hanging, being called by two functions, etc.

No idea why I hadn't thought of returning other functions, that's clearly
the right (safe) way.

I've read the old discussion, and nothing really struck me as to why lazy
lists never were implemented (or even the lazy list comprehensions). Of
course there were a few valid objections formulated, but it looks like the
discussion was forgotten as it evolved on to other subjects.

Without replacing the lists module, a lazylists (or streams, to follow what
was told back in 2000) module right next to it wouldn't do much harm. While
you don't gain a flawless integration of both concepts in the language, the
separate module leaves a standard way to do it if one ever comes to need it.

Was there any specific reason as to why it wasn't developed?

On Fri, Mar 20, 2009 at 3:56 AM, Ulf Wiger
<ulf.wiger@REDACTED>wrote:

> Frederic T-H wrote:
>
>> First time posting here, I've been reading this mailing lists for a few
>> months now, programming Erlang for a few months too.
>>
>> Python and its most functionnal parts is what eventually brought me to
>> Erlang. One feature that I loved in Python and instantly noticed was not
>> available in Erlang was generators. Generators are basically normal
>> functions, except they return an iterator, letting you fetch each result one
>> by one, effectively letting you work with constant memory. An example of the
>> way Python does it:
>>
>>   def gen(n):
>>       i = 0
>>       while i<n:
>>           yield i
>>           i+=1
>>       return
>>
>>   x = gen(2)
>>   x.next() # returns 0
>>   x.next() # returns 1
>>   x.next()  # throws an exception
>>
>
> This feels a bit reminiscent of lazy lists, which were
> discussed at some length on the erlang list quite
> recently (the year 2000, in fact):
>
> http://erlang.org/pipermail/erlang-questions/2000-October/001875.html
>
> BR,
> Ulf W
> --
> Ulf Wiger
> CTO, Erlang Training & Consulting Ltd
> http://www.erlang-consulting.com
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20090320/b6d53ffa/attachment.htm>


More information about the erlang-questions mailing list