Author: Donal K. Fellows <firstname.lastname@example.org> State: Final Type: Project Vote: Done Created: 7-Sept-2018 Post-History: Tcl-Version: 8.7 Keywords: Tcl, TclOO Vote-Results: 4/0/5 accepted Votes-For: DKF, JN, JD, AK Votes-Against: none Votes-Present: BG, KBK, DGP, FV, SL Tcl-Branch: tip-516
This TIP proposes to add some more operations to slots by updating the class that implements them.
Currently slots support setting (i.e., replacing all current slot items with a different list of items), appending (i.e., adding onto the end of the list), and clearing (i.e., setting the list to an empty list); the former two cases are moderated by the need for slot items to be unique, but that is a constraint enforced at the lower level. However, other basic operations are conceivable too, such as prepending an item and removing an item (with the latter needing a little care as it requires normalisation of the slot items). An example of how this last use case might be useful is when removing a behaviour from an object by removing a mixin from it; that's possible to do with the existing code, but quite awkward because it requires replacing the list of slot items with another list, and so it is an operation that we should provide by default.
This will add two new methods to the
This inserts the item (or items) at the front of the list of items in the slot. If there are no such arguments given, this does nothing; it is not an error to prepend no items.
This removes the item (or items) from the list of items in the slot. If an item is not present in the slot, this does nothing; it is not an error to remove a non-present item. If there are no such items in the arguments, this does nothing; it is not an error to remove no items.
To support this, an extra internal operation is added:
This returns the slotElement with a resolution operation applied to it. The meaning of this operation will depend on the kind of values held in a particular slot, but for a slot of classes then the relevant type of resolution would be command resolution. (The main slot method implementation classes will ensure that this method is always called in a context where the resolution context is that of the caller.)
This document has been placed in the public domain.