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

Björn-Egil Dahlberg <>
Sat Mar 5 15:38:23 CET 2016


I think those functions are nice things to add to the lists module. No
reason to hide them in some weird extra lib module.

The names though. Naming isn't easy. I actually had to look up the word
"intercalate" and now I know it roughly means "insert". Perhaps it really
best describes what the functions does but .. can't we find anything
shorter?

2016-03-05 15:22 GMT+01:00 Garrett Smith <>:

> On Sat, Mar 5, 2016 at 4:04 AM Jesper Louis Andersen <
> > wrote:
>
>> So to catch up:
>>
>> * On Richard's comments of other uses than for a string:
>>
>> The obvious use in Erlang is to produce iolist() types for binary data:
>> intersperse($, [<<"a">>, <<"b">>, <<"c">>]) is relatively common in my
>> code. The slightly less obvious use is to interleave a simplifier step in
>> between every optimization step of a compiler, but I've only done that once
>> in my life and I'm not sure it is that useful :)
>>
>
> Yep, iolists is the application I have for this.
>
>
>> * On the name choice of 'intersperse/intercalate':
>>
>> I think the semantics I'm aiming for is so close to the
>> OCaml(Core)/Haskell implementations I'm willing to reuse that name. Another
>> valid name is 'join' which is common in many other languages. I don't think
>> one is better than the other, but the FP roots in me says we should adopt
>> FP-language naming.
>>
>
> In looking over the naming conventions in Erlang, one might assume that
> the design pattern is for diversity rather than uniformity. That's a nice
> way to look at it I think.
>
> Personally I'd vote to converge on some standards rather than diverge -
> and taking cues from Erlang, and not the many many other languages, will
> help there. The clear analog is string:join. It's also short - saves
> valuable typing cycles!
>
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160305/3a9fa852/attachment.html>


More information about the erlang-questions mailing list