From 23affedf31b17edb45ed244246555bc9c68993e5 Mon Sep 17 00:00:00 2001 From: AnoBug Date: Wed, 31 Jan 2024 18:47:52 +0100 Subject: [PATCH] Added list utilities (diff, intersect) in alltools --- scripts/alltools.tcl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/scripts/alltools.tcl b/scripts/alltools.tcl index 8e3a1e8ed..2eee787d8 100644 --- a/scripts/alltools.tcl +++ b/scripts/alltools.tcl @@ -24,6 +24,7 @@ # Tothwolf 27Dec2003: added matchbotattrany, optimized ordnumber, # more minor changes # CrazyCat 18Oct2022: added achannels +# CrazyCat 31Jan2024: added lintersect and ldiff # ######################################## # @@ -127,6 +128,11 @@ # if the given number is between 1 and 15, return its text representation # else return the number given # +# lintersect +# returns a list of all elements in list1 that are present in list2 +# +# ldiff +# returns a list of all elements in list1 which are not in list2 # ## ## (other commands): @@ -384,6 +390,16 @@ proc number_to_number {number} { } } +proc lintersect {list1 list2 {option -exact}} { + if {$option ne "-nocase"} { set option -exact } + return [lmap x $list1 {expr {[lsearch $option $list2 $x] >= 0 ? $x : [continue]}}] +} + +proc ldiff {list1 list2 {option -exact}} { + if {$option ne "-nocase"} { set option -exact } + return [lmap x $list1 {expr {[lsearch $option $list2 $x] < 0 ? $x : [continue]}}] +} + # # other commands: #