Algorithmic lists

Thomas Arts thomas@REDACTED
Mon Oct 16 13:44:45 CEST 2000


Richard Carlsson wrote:
> 
> On Mon, 16 Oct 2000, Thomas Arts wrote:
> 
> > Ulf Wiger wrote:
> > >
> > > A list could be expressed in the following manner:
> > >
> > > [Head | fun(Head, F)]
> >
> > I don't really like that notation, since the tail of a list is no
> > longer a list now (but a function returning a list). I find it more
> > natural to return a tuple, a kind of continuation.
> 
> Yes, however, the cons cells are much more efficient in terms of memory
> allocation (in current Erlang implementations), only needing 2 words where
> a tuple needs three. I don't find it unreasonable to use cons cells for
> certain datatype representations, when they map so naturally to "cons or
> nil" as in this case. "cons cell" does not always have to imply "proper
> list", although for general purpose programming cons cells should not be
> used.

I am horrified by the idea to find the AXD 301 software full with 
cons cells, just in order to save those few bytes. In particular since
in these lazy lists, the elements have a very short lifetime (Ulf wants
to generate a side-effect and throw the value away), it would only
save you one word. If efficiency turns outto be so much an issue, than 
adding a new type to Erlang (similar to cons, but with different notiation,
would be preferable).


/Thomas



More information about the erlang-questions mailing list