I am just wondering if there is any way to create the same function with different count of parameters? Something like this:
sum_of_n(Num)->
sum_of_n(Num, 0);
sum_of_n(0, Accum)->
Accum;
sum_of_n(Num, Accum) ->
sum_of_n(Num - 1, Accum + Num).
As I see Erlang doesn’t allow to create the function with one and two parameters the same time. Is there a good way to create such function or I need use two different functions?
You can have two different functions with the same name, but different number of arguments:
In
export,fun, etc. you can refer to them asFunName/NumberOfArgs, e.g.