<< Prev | - Up - |
Loops are not only inspired by stateful programming; they are also particularly useful in the context of stateful data structures. For instance, we can use stacks to accumulate the results of a loop:
declare fun{Reverse List}
Acc = {NewStack}
in
for X in List do {Acc.push X} end
{Acc.toList}
end
{Inspect {Reverse [1 2 3 4]}}
<< Prev | - Up - |