From: Kevin R. <or...@gm...> - 2005-09-28 12:27:17
|
Hi, Well don't things just have a habit of keeping changing? Having almost got to the end of the road with the new map and list implementations I was happily updating the test suite only to run into a minor issue with the Map#removeKey(Object) method. The minor issue turned into a major one and back again, but an overhaul of the API is required... After a length, but useful, discussion with Steve, it is now quite obvious that removing a key from a list would not be a legal operation. When you remove a key from a map, the mapping for that key is removed. If the key is not present you can continue without much of a problem. What should you do if you remove a "key" from a list that is out of bounds? Also, when you remove a "key" from a list, you also shift everything at a higher index down by one position. Thus we actually need a "delete" operation which removes and compacts the mappings, but is only applicable to an extensible list. If the simple remove key operation(without compaction) were permitted on a List it would actually have to return a Map! The end result is something I had previously considered but left to one side, which is that the API must encapsulate immutability, updateability and extensibility. As such an immutable list will still be an immutable map, an updateable list will be an updateable map but an extensible list will *not* be an extensible map. Another nifty addition to the API will be the notion of a default action, rather than the current default value. The default value is only really applicable to one particular use of a map, but doesn't have a function in a list. Switching to a default action allows us to encapsulate the behavior of maps and lists is a nice neat way. If there is no mapping for a given key, the default action is called, but could do one of several things: return a static/dynamic value, throw an exception or execute custom code. The default default behavior for a map would be to return a static value, while for a list it would be throw an exception(index out of bounds). While converting MillScript to this new system, I also put a bit of thought how the VFS integrates into MillScript. At the moment a VFolder behaves like a list, you can iterate over each VEntry and index by an integer to obtain a specific entry. It's quite obvious now that this was the wrong choice and a VFolder should actually behave like a map, so I'm actually going to update the VFS API to ensure a VFolder is actually an immutable map. At some point in the future we can consider how update/extensible changes should be integrated too. So there's going to be a bit more delay before the next release, but I should point out that this is all working out quite nicely now. I've already converted the new XML parser to use this stuff and I have MillScript working with this new API on my development machine. As soon as I've got the missing map implementations done I'll commit the changes. Regards, Kev |