Suggestion: New table iterators

Robert Virding rv@REDACTED
Thu Oct 19 10:51:58 CEST 2000


Bjorn Gustavsson <bjorn@REDACTED> writes:
>I suggest that we add
>
>	ets:foldl(Fun, Acc, Table)
>	ets:foldr(Fun, Acc, Table)
>
>	dets:foldl(Fun, Acc, Table)
>	dets:foldr(Fun, Acc, Table)
>
>	mnesia:foldl(Fun, Acc, Table)
>	mnesia:foldr(Fun, Acc, Table)
>
>for iteration over tables.
>
>The difference between the foldl/3 and foldr/3 is the order in which the
>table elements are accessed. foldl/3 accesses from the first element to
>the last, while foldr/3 accesses the element from last to to first.
>Both functions are tail-recursive. The order is important only for ordered tables.

Definitely YES!  But I am not really convinced you need l/r.  Perhaps a
just fold/3 as well?  I generally think it is a good idea to add
iterators over to make it easier and, more importantly, clearer what 
you are doing.

>There is no need for map/2 or filter/3 functions, because they can easily
>be simulated with the fold functions:
>
>	my_tab2list(T) ->
>		ets:foldr(fun (E, Acc) -> [E|Acc] end, [], T).
>
>Besides, the reasonable semantics for map/2 and filter/3 would be that
>they modified the ets table or returned a new ets table, something we
>we are no prepared to implement now, but might be implemented in a future version.
>
>Any comments?

I definitely think that map and filter should return a modified table to
keep the general semantics of mapping and filtering consistent.  Not
returning a new table is OK here as the semantics of tables is
destructive.  With those semantics it would OK to add those functions
now but with relatively naive implementations.  At least filter.

	Robert

-- 
Robert Virding                          Tel: +46 (0)8 545 55 017
Alteon Web Systems                      Email: rv@REDACTED
S:t Eriksgatan 44                       WWW: http://www.bluetail.com/~rv
SE-112 34 Stockholm, SWEDEN
"Folk säger att jag inte bryr mig om någonting, men det skiter jag i".





More information about the erlang-questions mailing list