[erlang-questions] Proposal: add lists:intersperse/2 and lists:intercalate/2
Fri Mar 4 16:33:57 CET 2016
On 3/2/16 11:31 PM, Richard A. O'Keefe wrote:
> On 3/03/16 2:23 pm, Siraaj Khandkar wrote:
>>> interleave, v, OED, sense 3:
>>> "Computing and Telecommunications. To interfile (two or more
>>> digitized signals or sequences of information) by alternating
>>> between them; to alternate (one such signal or sequence) with
>>> others. Also, to divide (memory, etc.) between a number of
>>> different tasks by allocating successive segments to each in turn."
>>> (I must admit I hadn't encountered the word 'interfile' before.)
>> The way I understand it is:
>> - interleave: put 1 B between 2 As
> [A1,B1,A2,B2,A3,B3] will do.
> [A1,B1,A2,B2,A3,B3,A4] will do.
> Using the *same* B every time is not interleaving.
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.
If we have no uniqueness or distribution (i.e. how long until a repeat
is allowed) requirements for our two sequences, then there's no useful,
semantic distinction between a sequence of copied elements and a
sequence of randomly-generated elements.
Neither "interleaving" nor "interspersing" say anything about the
contents of the two sequences they operate on, where they differ is in
the degree to which they care about intervals between elements:
- "interleaving" promises a process which picks 1 element from A, then 1
element from B;
- "interspersing" only promises that some (undefined number of) elements
from A will end-up separated by some (undefined number of) elements from B.
One real problem, which goes against the requirement of the function
in-question, is that both, [a, b, a] and [a, b, a, b] seem to be allowed
by "interleave", but maybe not by "intersperse", but I'm not really sure
>> - intersperse: put M Bs between N As
> OED sense 1: "to scatter or sprinkle between or among other things;
> to place here and there in the course of something; to mingle
> dispersedly or at intervals."
> I don't think anyone looking at the OED would expect the Haskell
> function definition. The only justification for adopting the names
> intersperse and intercalate is that those *are* the names other
> not-entirely-dissimilar programming languages are using.
Just merely copying what has been done before, without looking into the
reasons, misses a valuable opportunity for improvement.
More information about the erlang-questions