1 ###### Macros.tcl ######################################################
3 # Copyright (C) 1998 William F. Schelter
4 # For distribution under GNU public License. See COPYING.tcl
6 # Time-stamp: "2024-03-20 15:13:37 villate"
8 # Procedures defined in this file:
10 # desetq - set the values for several variables
11 # assoc - returns the value of an option in an options list
12 # delassoc - removes an option from an options list
13 # putassoc - sets the value of an option in an options list
14 # ldelete - removes all ocurrences of an item in a list
16 ########################################################################
18 #-----------------------------------------------------------------------
19 # desetq lis1 lis2 -- for each vaiable name in lis1, set its value equal
20 # to the corresponding value in list lis2 (in the scope where desetq was
21 # issued). lis1 and lis2 must be two list with the same length.
22 #-----------------------------------------------------------------------
23 proc desetq
{lis1 lis2
} {
24 foreach var
$lis1 value
$lis2 { uplevel 1 set $var [list $value]}}
26 ###### Options parsing functions ######################################
27 # Options are assumed to be a list of keywords followed by a single vlaue
29 #-----------------------------------------------------------------------
30 # assoc key lis args -- returns the value of option with keywork key in
31 # options list lis, or the optional value args if lis doesn't have that
33 #-----------------------------------------------------------------------
34 proc assoc
{key lis args
} {
35 foreach {k val
} $lis {if {$k eq
$key} {return $val}}
36 return [lindex $args 0]}
38 #-----------------------------------------------------------------------
39 # delassoc key lis -- returns the options list lis excluding the option
41 #-----------------------------------------------------------------------
42 proc delassoc
{key lis
} {
44 foreach {k val
} $lis {
45 if {$k ne
$key} {lappend new
$k $val}}
48 #-----------------------------------------------------------------------
49 # putassoc key lis value -- returns the options list lis with the keyword
50 # key associated to value. If the keyword key was already present its
51 # associated value is replaced by value
52 #-----------------------------------------------------------------------
53 proc putassoc
{key lis value
} {
56 foreach {k val
} $lis {
61 if {!$done} {lappend new
$key $value }
63 ###### End options parsing functions #################################
65 #-----------------------------------------------------------------------
66 # intersect lis1 lis2 -- returns the list of common elements of the two
68 #-----------------------------------------------------------------------
69 proc intersect
{lis1 lis2
} {
73 if {$v eq
$u} {lappend new
$v}}}
76 #-----------------------------------------------------------------------
77 # ldelete item lis -- returns list lis with all ocurrences of item
79 #-----------------------------------------------------------------------
80 proc ldelete
{item lis
} {
81 while {[set ind
[lsearch $lis $item]] >= 0} {
82 set lis
[concat [lrange $lis 0 [expr {$ind-1}]] \
83 [lrange $lis [expr {$ind+1}] end
]]}
86 ## endsource macros.tcl