using lremove command

Altair Forum User
Altair Forum User
Altair Employee
edited October 2020 in Community Q&A

Hi,

i am facing some problem with lremove command in HM10.0,

i had written a macro which is using lremove command and i have included 'package require Tclx' also ,

the same macro is working with HM8 and HM9.0 but was giving error invalid command lremove in HM10.0.] (*,)

if i open the command window in HM10 and run my macro it working fine , but without opening command window its not working.

Can any body, let me know how to fix the same.

Looking forward to your replies.

Thanks and regards

Ramu B

Answers

  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited November 2009

    Hi Ramu,

    as far as I know lremove is a procedure from tkcon:

    ## lremove - remove items from a list# OPTS:#   -all	remove all instances of each item#   -glob	remove all instances matching glob pattern#   -regexp	remove all instances matching regexp pattern# ARGS:	l	a list to remove items from#	args	items to remove (these are 'join'ed together)##proc lremove {args} {    array set opts {-all 0 pattern -exact}    while {[string match -* [lindex $args 0]]} {	switch -glob -- [lindex $args 0] {	    -a*	{ set opts(-all) 1 }	    -g*	{ set opts(pattern) -glob }	    -r*	{ set opts(pattern) -regexp }	    --	{ set args [lreplace $args 0 0]; break }	    default {return -code error 'unknown option \'[lindex $args 0]\''}	}	set args [lreplace $args 0 0]    }    set l [lindex $args 0]    foreach i [join [lreplace $args 0 0]] {	if {[set ix [lsearch $opts(pattern) $l $i]] == -1} continue	set l [lreplace $l $ix $ix]	if {$opts(-all)} {	    while {[set ix [lsearch $opts(pattern) $l $i]] != -1} {		set l [lreplace $l $ix $ix]	    }	}    }    return $l}

    I think in hm10 tkcon is not opened upon startup and hidden as in hm versions before - therefore you'll miss it. But you can use the info command to check wheter lremove exists and if not include the code above:

    if {[info proc lremove] == ''} {    #include code}
  • Altair Forum User
    Altair Forum User
    Altair Employee
    edited December 2009

    Hi,

    i have tried the way u mentioned its working well, but in the macro i am using some puts command to write some messages to console, there it was showing the error like stdout was not open....

    this was happening after adding the lremove command code...

    how to fix the same and what is the reason for happening like this...

    Regards

    Ramu

    I had the same problem with some of my scripts with hm10.

    I wrapped the rare puts statements by catch:

    catch {puts 'hi there'}

    Maybe there's a more elegant method but that was what first came to my mind: getting output if console is shown and raising no error if not ...