diff options
| author | dkf <donal.k.fellows@manchester.ac.uk> | 2018-09-27 07:22:42 (GMT) |
|---|---|---|
| committer | dkf <donal.k.fellows@manchester.ac.uk> | 2018-09-27 07:22:42 (GMT) |
| commit | efa79f01e6397ee0ba17d04a6433e47569db79c6 (patch) | |
| tree | 63a4bc0a84705100b04124e660e8fa3b87d1f8a5 /generic/tclOOScript.tcl | |
| parent | 9f745ab1cdb74cb094d577d0b4f91dbd842ec5ef (diff) | |
| parent | 90e3bdc291f94c2e3ff1c4e5b0edb6e203966147 (diff) | |
| download | tcl-efa79f01e6397ee0ba17d04a6433e47569db79c6.zip tcl-efa79f01e6397ee0ba17d04a6433e47569db79c6.tar.gz tcl-efa79f01e6397ee0ba17d04a6433e47569db79c6.tar.bz2 | |
Implementation of TIP 516: More OO Slot Operations
Diffstat (limited to 'generic/tclOOScript.tcl')
| -rw-r--r-- | generic/tclOOScript.tcl | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/generic/tclOOScript.tcl b/generic/tclOOScript.tcl index d3706ce..a48eab5 100644 --- a/generic/tclOOScript.tcl +++ b/generic/tclOOScript.tcl @@ -276,6 +276,20 @@ # ------------------------------------------------------------------ # + # Slot Resolve -- + # + # Helper that lets a slot convert a list of arguments of a + # particular type to their canonical forms. Defaults to doing + # nothing (suitable for simple strings). + # + # ------------------------------------------------------------------ + + method Resolve list { + return $list + } + + # ------------------------------------------------------------------ + # # Slot -set, -append, -clear, --default-operation -- # # Standard public slot operations. If a slot can't figure out @@ -283,12 +297,32 @@ # # ------------------------------------------------------------------ - method -set args {tailcall my Set $args} + method -set args { + set my [namespace which my] + set args [lmap a $args {uplevel 1 [list $my Resolve $a]}] + tailcall my Set $args + } method -append args { - set current [uplevel 1 [list [namespace which my] Get]] + set my [namespace which my] + set args [lmap a $args {uplevel 1 [list $my Resolve $a]}] + set current [uplevel 1 [list $my Get]] tailcall my Set [list {*}$current {*}$args] } method -clear {} {tailcall my Set {}} + method -prepend args { + set my [namespace which my] + set args [lmap a $args {uplevel 1 [list $my Resolve $a]}] + set current [uplevel 1 [list $my Get]] + tailcall my Set [list {*}$args {*}$current] + } + method -remove args { + set my [namespace which my] + set args [lmap a $args {uplevel 1 [list $my Resolve $a]}] + set current [uplevel 1 [list $my Get]] + tailcall my Set [lmap val $current { + if {$val in $args} continue else {set val} + }] + } # Default handling forward --default-operation my -append @@ -303,7 +337,7 @@ } # Set up what is exported and what isn't - export -set -append -clear + export -set -append -clear -prepend -remove unexport unknown destroy } |
