<div dir="ltr"><div class="gmail_default" style="font-family:monospace,monospace">For Haskell's intersperse, we have lists:join/2.</div><div class="gmail_default" style="font-family:monospace,monospace">add-between offers rather more options, but that's Racket for you.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, 24 Mar 2021 at 09:18, Siraaj Khandkar <<a href="mailto:siraaj@khandkar.net" target="_blank">siraaj@khandkar.net</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Greetings Erlangers,<br>
<br>
Nothing serious, just some fun here. I stumbled on the function<br>
"add-between" in Racket stdlib, which reminded me of the lively, lolzy <br>
debate we had here 5 years ago :-D<br>
<br>
$ racket<br>
Welcome to Racket v7.9 [bc].<br>
> (add-between '(a b c d) 0)<br>
'(a 0 b 0 c 0 d)<br>
><br>
<br>
<a href="https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._add-between%29%29" rel="noreferrer" target="_blank">https://docs.racket-lang.org/reference/pairs.html#%28def._%28%28lib._racket%2Flist..rkt%29._add-between%29%29</a><br>
<br>
<br>
On 3/2/16 12:02 PM, Siraaj Khandkar wrote:<br>
> On 3/2/16 9:47 AM, Jesper Louis Andersen wrote:<br>
>> Hi Erlangers,<br>
>><br>
>> I'd really like to add two functions to the lists module from Haskell:<br>
>><br>
>> intersperse(List, Seperator) produces a list where each element is<br>
>> separated by separator, i.e.<br>
>><br>
>> X = [1,2,3]<br>
>> [1, x, 2, x, 3] = lists:intersperse(X, x),<br>
>><br>
>> and it's cousin, intercalate(ListOfLists, Separator) is<br>
>> append(intersperse(ListOfLists, Seperator)), i.e,<br>
>><br>
>> Y = ["a", "b", "c"]<br>
>> "a, b, c" = lists:intercalate(Y, ", "),<br>
>><br>
>> The implementations are straightforward and easy to write tests for, even<br>
>> property based tests if needed.<br>
>><br>
>> The rationale for this proposal is that I find myself implementing this<br>
>> function again and again in every project I write, and it is highly<br>
>> generic. It belongs in a typical list module. OCaml libraries add it.<br>
>> Haskell's Data.List has it. I believe Erlang, being a practical language,<br>
>> should have it as well.<br>
>><br>
>> Thoughts?<br>
> <br>
> +1<br>
> <br>
> Though I prefer the name "interleave" to "intersperse", since its <br>
> meaning is more-precise and closer to the intended behavior here.<br>
</blockquote></div>