Suppose I have to update a list with each call to a function, such that, the previous element of the list are preserved.
Here is my attempt:
local
val all_list = [];
in
fun insert (x:int) : string = int2string (list_len( ((all_list@[x])) ) )
end;
The problem is that each time I call to insert, I get the output "1", which indicates that the list is initiated to []
again.
However I was expecting output of "1"
for the first call to insert, and "2"
for the second call,...etc.
I am not able to come with a workaround. How should it be done?