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

Richard A. O'Keefe <>
Wed Mar 9 00:18:44 CET 2016


On 8/03/16 8:24 pm, Chandru wrote:
> On 7 March 2016 at 16:04, Loïc Hoguin < 
> <mailto:>> wrote:
>
>
>     I am completely with you on that. If the function was called
>     intercalculate I'd never find it and would continue writing my own.
>
>
> I second this. I'm part of the vast number of unwashed masses who've 
> never heard of the term intercalculate,

Please, if you are going to pour scorn on a word, at least COPY
the thing correctly.  The proposal is not "intercalCULate" but 
"intercalate",
and it's a real English word with a history going back at least 400 years
in English, 500 years in French, and 2500 years in Latin.

I think it's a bad name not because nobody knows what it means (I'd expect
any skilled native speaker of English to have met it several times) but 
because
it means to insert ONE (unusual) thing into a sequence of (ordinary) things,
as in one leap day or one leap month into a year.

> and if I came across it in a developer's code would think that they 
> were being a bit too clever. Like many others I have written this 
> piece of code several times and invariably named it 
> 'concat_with_separator' - a mouthful but it conveys (at least to me) 
> what exactly the function is doing.
Since 1997 (if not before) the SML Basis Library has included

fun concatWith _ [] = ""
   | concatWith separator (string :: strings) =
     concat (string :: map (fn x => separator^x) strings)

(*) I am using that as a specification.  It would be a horrible 
implementation.

Since 2015 that library includes

fun concatWithMap separator f data =
    concatWith separator (map f data)

except that the point of concatWithMap is to fuse the calculations.
concat{,With}{,Map} are available on all vector-like types in the SML Basis.

Would those names do?






More information about the erlang-questions mailing list