functional programming - Loops in SML/NJ -
I am very new to SNL / NJ and wondering how I can fulfill the following:
foo (luggage, counter) {while (counter> gt; 0) {bar (luggage); Reply1; } Return; } Something like this, but how do I reduce it?:
foo (luggage, counter) = counter> 0 times (luggage) ??? // How do I reduce the counter?I agree with other contributors that you usually refer to Rickshaw instead of loop and mutation Should do so in a functional language to do so.
If you really want to use mutations and loops, then you have to use the data structure that uses a reference that is a type of "volatile cell". You assign references with the
reffunction, passing it the initial content you!can access content using the operator. And you set up new content using the: =operator. So the literal translation of the code given above will be as follows: As you can see, the syntax is really ugly and this is another reason why people avoid it.Funny foo (luggage, counter-start) = val counter = referee counter- while restarting! Counter & gt; 0 times (bar accessories; counter: =! Counter-1) end;
Comments
Post a Comment