Suggestion: New table iterators

Jakob Cederlund på UAB jakob@REDACTED
Thu Oct 19 11:01:04 CEST 2000


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.

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.)

/Jakob




More information about the erlang-questions mailing list