Tail/Non tail recursion
Richard A. O'Keefe
Tue Sep 2 01:06:10 CEST 2003
I mentioned how
f([H|T]) -> [X+1 | f(X)];
f() -> .
could be tail recursive.
Thomas Lindgren <> wrote:
First, let me say that I don't support user-accessible
destructive operations in Erlang. Keep the language as
pure as possible. Under the hood, however, destructive
updates are interesting.
I am rather baffled by this, in context.
The scheme I alluded to doesn't use destructive operations,
only initialising writes. (While a data structure might be
constructed incrementally, it would only become readable once
it was fully initialised.)
It does admittedly destroy the "all pointers point downwards" property
Erlang might otherwise have enjoyed, but that is another matter.
The obvious next step would be to automatically detect
when to do this, and to introduce assignments and
extra "pointer arguments". That would mean one could
evaluate the effect on real code.
For destructive update generally, many people have worked on the
problem of automatically detecting when it can safely be used.
In many ways the simplest answer is that found in the Clean and Mercury
"type" systems. It's not clear to me whether such methods can easily
be adapted to Erlang's dynamic module system. (Module replacement
is very much a "user-accessible destructve operation", by the way.)
More information about the erlang-questions