Suggestion: New table iterators

Ulf Wiger <>
Thu Oct 19 11:17:07 CEST 2000

On Thu, 19 Oct 2000, Jakob Cederlund på UAB wrote:

>At 10:39 2000-10-19 +0200, Bjorn Gustavsson wrote:
>>I suggest that we add
>>         ets:foldl(Fun, Acc, Table)
>>         ets:foldr(Fun, Acc, Table)
>Hmm... it's easily done, but is it the right way?
>What you want is a way to iterate over containers, that is not tied to the 
>implementation of the container.
>The way of iterating in erlang, recursing with [Car | Cdr] is tied
>to the list type. Lazy evaluation, with language support, could be
>one way of replacing the | Cdr with a fun-call, without having to
>rewrite a lot of code.

This is true. After shying away a bit from the discussion on Lazy
evaluation, I've decided to punt, and try to get support for the
common list iterator functions (including list comprehensions) over
ets and mnesia tables.

The standard [H|T] syntax can be augmented through the [H|fun()]
trick - which seems to be frowned upon(?), but not forbidden - leaving
most of the code intact. We will probably use that (with care) in
places where it solves the problem nicely.

>Using foldl or foldr instead of [Car | Cdr] is another way of doing
>it, perhaps yielding less readable code. But it's still not easy to
>change underlying representation.
>And it doesn't solve the initial problem, that there is no easy way
>for isolating the algorithms on containers from the implementation
>of the container. (Call it OOP or generic programming or whatever.)

Personally, I still think the [H|fun()] trick is the best candidate
for solving that quickly, but I'm fully prepared to let that go if it
confuses things or risks being a dead end in a longer perspective.

Ulf Wiger                                    tfn: +46  8 719 81 95
Strategic Product & System Management        mob: +46 70 519 81 95
Ericsson Telecom AB,              Datacom Networks and IP Services
Varuvägen 9, Älvsjö,                    S-126 25 Stockholm, Sweden

More information about the erlang-questions mailing list