Slower than Windoze
Sometimes I can be incredibly slow on the uptake.
It was about 5 years ago that I first started using agents. Classes such as ARRAY all had a feature named do_all. Pretty soon, I found the need to iterate over two such structures simultaneously, so for an ARRAY-like class that we use at work, I added a feature do_all_with_index, which passes the position within the structure, as well as the element value, to the agent. Then all I had to do was pass a reference to the second structure as a closed argument to the agent.
This feature was then soon added to the standard libraries at my request. I use it all the time.
It's taken me until this morning to realize it is completely unnecessary. If I can pass a reference to the other structure, then I can also pass a cell containing the value of the index, initializing it to `lower', and have the agent increment the contents of the cell at the end of every call (with a postcondition to prove it happens, of course).
Even MS-Windoze can (usually) complete such a simple calculation quicker than that!
For_all_with_index and there_exists_with_index are still necessary (as using the same trick would violate CQS).
Example Code?
Colin,
Can you provide an example?
Thanks!