Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why does this code with TCL Upvar command generate an error?

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 ??

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading