3 ms·
Hope is pretty close to the Erlang version: factorial(0) -> 1; factorial(N) -> N * factorial(N-1). At first I was suspicious of function head clauses
by rdtsc 7y ago
Hope is pretty close to the Erlang version:
factorial(0) -> 1;
factorial(N) -> N * factorial(N-1).
At first I was suspicious of function head clauses but have really come to like them. They make the code much more readable and easier to maintain. You can add another clause and keep your change diff small. It could be a general catch-all clause at the end, or a more specific, restricted case at the front and so on.
Tracing is also much nicer. Fire up dbg or recon and it's easy to pick off a particular clause without much effort.