[erlang-questions] Proposal: add lists:intersperse/2 and lists:intercalate/2
Thu Mar 3 02:23:55 CET 2016
On 3/2/16 7:41 PM, Richard A. O'Keefe wrote:
> On 3/03/16 6:02 am, Siraaj Khandkar wrote:
>> Though I prefer the name "interleave" to "intersperse", since its
>> meaning is more-precise and closer to the intended behavior here.
> No, interleaving requires *two* sequences. This is interleave:
> interleave(, ) -> ;
> interleave([X|Xs], [Y|Ys]) -> [X,Y|interleave(Xs,Ys)].
> 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
- intersperse: put M Bs between N As
i.e. "intersperse" is more-general - interval length is unspecified.
Is this wrong?
More information about the erlang-questions