Author: Donal K. Fellows <[email protected]>
State: Draft
Type: Project
Vote: In progress
Created: 22-Feb-2020
Post-History:
Tcl-Version: 8.7
Keywords: Tcl, TclOO, slots
Tcl-Branch: tip-567
Abstract
This TIP adds an operation to slots to make it easier to manage slots that have set-like semantics.
Rationale
Some slots are very much like slots, in that repeated entries are forbidden. Examples of this are the superclass slot of classes, and the mixins slots of classes and instances. This matters because there is sometimes a need to ensure that a particular value is in a slot without basing the operation on whether the value is already there. It's possible, of course, to do this with the existing operations, but the code to do so is moderately complex due to the need to handle resolution of the class names; it's simpler to add the operation to the slot itself.
This TIP fixes a subtle bug in the implementation of TIP #500 found during the development of the implementation of TIP #560.
Specification
The following method will be added to the class ::oo::Slot:
slot -appendifnew arg...
Each arg (of which there may be arbitrarily many) is appended to the slot, slot, if the arg (after whatever resolution slot normally applies) is not already present in the internal list maintained by slot. If any arg is not a valid item for slot, an error message will be generated. The result will be the empty string on success.
The slots containing classes (specifically superclass and mixin, the latter on both classes and instances) additionally gain the requirement that their elements be unique within the slot.
Implementation
The core of the implementation is simply this:
method -appendifnew -export args {
set my [namespace which my]
set current [uplevel 1 [list $my Get]]
foreach a $args {
set a [uplevel 1 [list $my Resolve $a]]
if {$a ni $current} {
lappend current $a
}
}
tailcall my Set $current
}
The full implementation (including a number of bugfixes enabled by this) is on
the tip-567
branch.
Copyright
This document is placed in public domain.