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

Garrett Smith g@REDACTED
Sat Mar 5 15:22:24 CET 2016


On Sat, Mar 5, 2016 at 4:04 AM Jesper Louis Andersen <
jesper.louis.andersen@REDACTED> 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!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20160305/a11d16f3/attachment.htm>


More information about the erlang-questions mailing list