[erlang-questions] learning Erlang: factoring primes

Kostis Sagonas kostis@REDACTED
Fri May 4 10:07:31 CEST 2007


Matthias Lang wrote:
> The programming style is fine. I only see trivial things which are
> hardly worth mentioning:
> 
>   - You don't need to quote atoms like 'factor' (in your compile comment)
>   - The program currently hangs for negative numbers
> 
> It can be simplified a bit, though it's already pretty good. You can
> rewrite next_factor in two clauses like this:
> 
>   first_factor(N, M) when N rem M == 0 -> 
>     M;
>   first_factor(N, M) -> 
>     first_factor(N, M+1).

Please, do not use == for arithmetic comparisons with integers (*).
It's brain damage from C.

Learn to use =:= instead.  It's more kosher.

Kostis

(*) Unless you really mean it. But even in those cases think again.



More information about the erlang-questions mailing list