I have started some hands on in Erlang and I am getting : ** 1: syntax error before: '->' ** whenever i am declaring any function for eg. to calculate sum of a list (this is experimental, of cource there is Built In Function for find sum of a list).
sum([]) -> 0;
sum([H | T]) -> H + sum(T).
in erl shell (v 5.5.5).
Thanks in advance
You can’t define functions in the shell using the same syntax as in an erl file.
You can define fun’s though.
Syntax in the shell needs to be:
Note that recursive anonymous functions (which this is) are defined in an ugly way. You basically have to pass the function as an argument to itself.