Open vaivaswatha opened 5 years ago
Note that the design for this issue may affect the design of issue #516.
Consider adding iterators for maps as well. This would definitely impact the design of #516.
FWIW, Solidity does not allow contracts to iterate over the keys of a mapping.
I thought about this a while ago, and I couldn't come up with a better way to do it than what @vaivaswatha suggests above, so maybe we should just retire this issue?
Speaking of the pure fragment of Scilla, we could expose the underlying OCaml map fold as a primitive.
Btw, this would allow us to retire builtin to_list
as this one could be implemented in Scilla then (although we might want to keep it because e.g. of performance reasons).
Can we guarantee the traversal order? i suppose we can, since we appear to be able to guarantee determinism of Hashtable.to_list
or whatever it's called in OCaml.
Right, citing the OCaml manual:
If the hash table was created in non-randomized mode, the order in which the bindings are enumerated is reproducible between successive runs of the program, and even between minor versions of OCaml. For randomized hash tables, the order of enumeration is entirely random.
The current way to iterate over
Map
s is to convert it to a list (builtin to_list
) and then fold over the list. It may be faster (lesser gas consumed) to directly iterate (fold) over theMap
.