Defender N < M may be useful. In general, you do not need a guard for equality; you can use pattern matching.
create(N) -> create(1, N). create(M, M) -> [M]; create(N, M) when N < M -> [N | create(N + 1, M)].
You also usually want to write functions so that they are tail recursive, in which the general idiom should be written to the head and then reversed at the end.
create(N) -> create(1, N, []). create(M, M, Acc) -> lists:reverse([M | Acc]); create(N, M, Acc) when N < M -> create(N + 1, M, [N | Acc]).
(Of course, in this particular example, you can alternatively build the results in the reverse order, up to 1 instead of M, which would make calling lists:reverse unnecessary.)
If create/2 (or create/3 ) is not exported, and you set the corresponding protector to create/1 , an additional N < M protector may be overflowed. Usually I test only exported functions and trust my own internal functions.
source share