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

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -