Overuse of guards in Erlang?
Posted
by dagda1
on Stack Overflow
See other posts from Stack Overflow
or by dagda1
Published on 2010-04-12T22:02:57Z
Indexed on
2010/04/12
22:23 UTC
Read the original article
Hit count: 350
erlang
Hi,
I have the following function that takes a number like 5 and creates a list of all the numbers from 1 to that number so create(5). returns [1,2,3,4,5].
I have over used guards I think and was wondering if there is a better way to write the following:
create(N) ->
create(1, N).
create(N,M) when N =:= M ->
[N];
create(N,M) when N < M ->
[N] ++ create(N + 1, M).
Thanks,
Paul
© Stack Overflow or respective owner