So I thought I understood how the TCL upvar command worked, but for some reason I cannot seem to trace why this code generates an error -
#!/usr/bin/env tclsh
proc run_check {} {
set src dut.acore.B2.Vin
set conlist1 [list dut.acore.B2.Vin dut.acore.N1__Bidir_2__ddiscrete_5.Aout dut.acore.DCORE.CLK]
puts $conlist1
set conlist2 [_lremove $conlist1 $src true]
puts $conlist2
}
proc _lremove {listName val {byval false}} {
upvar 1 $listName list
puts $list
#if {$byval} {
# set list [lsearch -all -inline -not $list $val]
#} else {
# set list [lreplace $list $val $val]
#}
return $__list
}
######################################
##Run Command
######################################
puts [run_check]
On running this code, I get the following -
(base) ./remove.tcl
dut.acore.B2.Vin dut.acore.N1__Bidir_2__ddiscrete_5.Aout dut.acore.DCORE.CLK
can't read "list": no such variable
while executing
"puts $list"
(procedure "_lremove" line 4)
invoked from within
"_lremove $conlist1 $src true"
(procedure "run_check" line 6)
invoked from within
"run_check"
invoked from within
"puts [run_check]"
(file "./remove.tcl" line 35)
Any thoughts on this ??
CodePudding user response:
When you call _lremove you need to pass it the variable name conlist1
but you are passing its value. Change
set conlist2 [_lremove $conlist1 $src true]
to
set conlist2 [_lremove conlist1 $src true]