push_element/2 - efficient sliding window

Vlad Dumitrescu XX (LN/EAB) vlad.xx.dumitrescu@REDACTED
Fri Aug 12 09:47:08 CEST 2005


> -----Original Message-----
> From: owner-erlang-questions@REDACTED
> [mailto:owner-erlang-questions@REDACTED]On Behalf Of Ulf Wiger
> Another thing I'd like to see for tuples is a syntax
> addition:
> 
> tag_search([{Tag | _} = T|_], Tag) ->
>     {value, T};
> ...
> 
> That is, describing the "tail" of a tuple in a manner
> similar to that of lists. This form is actually used
> in some places in the documentation! Most likely because
> it's very convenient. It could also be used to improve
> backwards compatibility, since new elements in a tuple
> are usually added last to preserve order.

Dou you think it should also work as a constructor?
	Tuple2 = { Elem | Tuple1}

Elegance would require it, but it would be quite inefficient to use tuples in this way (where in fact lists are needed) because one needs to copy the tuple contents, whereas adding to the head of a list is constant time.

regards,
Vlad



More information about the erlang-questions mailing list