[erlang-questions] iterators in Erlang

Richard Carlsson <>
Wed Oct 25 16:37:05 CEST 2006


James Hague wrote:
> 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.

It's simply much cheaper to do this sort of thing using coroutines.
With processes, you have to send a message to request the next element
and wait for the reply, and even if that can be pretty fast in Erlang,
it is not nearly as fast as a coroutine call. Another thing is that a
coroutine cannot suddenly go away and leave the client hanging. So,
if you had some kind of generator construct in Erlang, would you want
it to map onto processes, or would you prefer real coroutines? Perhaps
a good start would be if someone wrote a generator library based on
processes.

There was some early research by Erik Stenman of the HiPE project
on creating shortcuts for request/reply without going through the
scheduler and the message queue, but it never got beyond experimental.

See Erik's Ph.D. thesis for details:
http://www.diva-portal.org/diva/getDocument?urn_nbn_se_uu_diva-2688-1__fulltext.pdf

	/Richard




More information about the erlang-questions mailing list