How does one split a list which is passed as an argument to a function and tag each element with a number?
The problem I have is how to increment in erlang as there are no for loops.
Thanks
How does one split a list which is passed as an argument to a function and tag each element with a number?
The problem I have is how to increment in erlang as there are no for loops.
Thanks
Is this what you're trying to do?
tagger(List) ->
tagger(List, 0).
tagger([Head|Tail], Index) ->
[{Head, Index}|tagger(Tail, Index + 1)];
tagger([], _Index) ->
[].
Because if it is, you can use lists:mapfoldl
:
lists:mapfoldl(fun (A, AccIn) -> {{A, AccIn}, AccIn + 1} end, 0, List).