Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Erlang: which pattern matching is more efficient (lists)?

I'm going through "Pragmatic Programming Erlang" where there is a function defined like this:

split("\r\n\r\n" ++ T, L) -> {reverse(L), T};
split([H|T], L) -> split(T, [H|L]);
split([], _) -> more.

What interests me is first match, namely "\r\n\r\n" ++ T - is there performance difference between such a pattern and similar one, that I came up with: [13,10,13,10|T]? Or are they equivalent?

I know it's very simple question and that I could (probably) check it myself, but if there is a difference, I'd like to know why that is the case.

Thanks!

like image 943
cji Avatar asked Nov 28 '11 16:11

cji


1 Answers

"\r\n\r\n" ++ T is just syntax sugar for [13,10,13,10|T]. It should perform same. If not there is something wrong ;-)

like image 89
Hynek -Pichi- Vychodil Avatar answered Oct 07 '22 07:10

Hynek -Pichi- Vychodil