recursion - What are the two ways of maintaining state between tail-recursive instances of a function in Erlang? -
The equivalent in a procedural language (for example in Java) will be the local variable (or frequency variable), outside of a loop Use content to be used and update them How can I do in Erlang?
You pass state as a parameter in the recurring call. Example loop that receives NN message and returns it as a list:
Loop (N) - & gt; Loop (n, 0, []) loop (n, count, message) when calculation & lt; N - & gt; Receive messages - & gt; Loop (n, count + 1, [message | message]) end; Loop (_, _, Message) List: Reverse (MGS)
Comments
Post a Comment