[erlang-questions] [enhancement] string:split/2

Richard O'Keefe <>
Fri Oct 10 01:21:44 CEST 2008

On 9 Oct 2008, at 7:43 pm, Edwin Fine wrote:
> I'm assuming you are providing this code as an "executable  
> requirements document." I was rather hoping that it could be  
> implemented as a BIF.
> I'll have to study your code below so I can learn some "fast and  
> fancy" Erlang!

Well, no.  I was providing the code as a first draft of what
could be dropped into string.erl.  I see no reason why it should
be a BIF, if by that you mean something implemented in C.

If the performance of unjoining should be a bottleneck in some
program, after getting over my astonishment I would recommend
unrolling.  For example,

> unjoin0([C|Cs]) ->
>    [[C] | unjoin0(Cs)];
> unjoin0([]) ->
>    [].

would become

unjoin0([A,B,C,D|S]) -> [[A],[B],[C],[D] | unjoin0(S);
unjoin0([A,B,C])     -> [[A],[B],[C]];
unjoin0([A,B])       -> [[A],[B]];
unjoin0([A])         -> [[A]];
unjoin0([])          -> [].

That plus HiPE can often do surprisingly well.

But this is something to do AFTER measurement!

More information about the erlang-questions mailing list