archie/tcl-dp/library/ldelete.tcl
2024-05-27 16:13:40 +02:00

23 lines
416 B
Tcl

# ldelete.tcl --
#
# This file contains a list element deletion utility procedure.
# It is used in the whiteboard example.
#
# ldelete - search a list for an item and delete the first one found;
# - returns new list;
#
# example: ldelete {a b c a} a ==> b c a
#
proc ldelete {list elt} {
set index [lsearch $list $elt];
if {$index >= 0} {
return [lreplace $list $index $index];
}
return $list;
}