# [erlang-questions] Proposal: add lists:intersperse/2 and lists:intercalate/2

Richard A. O'Keefe <>
Mon Mar 7 04:18:46 CET 2016

On 5/03/16 4:33 am, Siraaj Khandkar wrote:
>
> The notion of sameness here is problematic, since you're now requiring
> that the above-quoted "sequences of information" are sets, which is
> unlikely the intended meaning.

You just lost me.  I was requiring that the sequences be SEQUENCES.
How does anything I wrote require them to be sets?

Here's what I was saying:
going from [a,b,c] and [1,2,3] to [a,1,b,2,c,3] *IS* interleaving
going from [a,b,c] and 0 to [a,0,b,0,c,0] is *NOT* interleaving.

The question is not whether a sequence contains repeated elements
but a question as to whether it *IS* a sequence in the first place,
I am happy to call [a,b,c] [0,0,0] -> [a,0,b,0,c,0] interleaving.

interleave([X|Xs], [Y|Ys]) -> [X,Y|interleave(Xs,Ys)];
interleave([],    [])    -> [].

Didn't I give that very code?  This DOESN'T care whether there are
repeated elements in either sequence.  It DOES care that it is given
two lists, not a list and a single element.  Again, what I'm saying is
not that there is a problem with lists that *happen* to contain
duplicate elements, but that

not_interleave([X,Y|Zs], S) -> [X,S|not_interleave([Y|Zs], S)];
not_interleave(End,    _) -> End.

is not interleaving.

We agree that "interleaving" does not "say anything about the
contents of the two sequences", which is why I didn't say anything
about the contents of the two sequences.  We also agree that
it "operate[s] on" "two sequences", not one sequence and one
something else, which was my whole point.

Sigh.