[erlang-questions] generating primes

Attila Babo babo.online@REDACTED
Thu Oct 16 21:54:10 CEST 2008

Using an accumulator for your sieve_filter functions pays back, it's
around 30 percent faster than the original version. Erlang optimized
the other functions quite nicely, but here the tail recursive version
is better by a clean margin.

sf(_, _, [], R) -> R;
sf(F, I, [F|T], R) -> sf(F + I, I, T, R);
sf(F, I, [H|T], R) when H > F-> sf(F + I, I, T, [H|R]);
sf(F, I, [H|T], R) -> sf(F, I, T, [H|R]).


More information about the erlang-questions mailing list