Last night, I get the solution for deleting tcl list item. Actually this solution can be found in tcl manual. It is my mistake for take things easy and misunderstood the behaviour of lreplace command.
Deleting a list item in a tcl list is actually straight forward. But of course quite confusing.
Originally my procedure to delete list item is like this ( not the right one - of course):
proc ldelete { list item} {
# get the index,ix for item in tcl list
set ix [lsearch -exact $list $item]
#ix is greater then zero if the item is in the lsit
if {$ix>=0} {
# replace the item at index ix until index ix with nothing (aka - delete the item)
lreplace $list $ix $ix
else {
return $list
}
}
At around 11.00 pm last night i found out that the error is actually at the command:
"lreplace $list $ix $ix"The command delete list item at index ix and returns the modified list but without updating it.
So the solution is simply like this.
set list [lreplace $list $ix $ix]I'm very happy today! More programming !A lot to learn!
BTW, Thanks taufiq for helping me transferring the computers from IP-tech lab to WSN lab.


2 comments
congratulation on your successful, work hard more, I sure you can beat summayah, for summayah" you need beat this old guy", haha
haha. apa ni taufiq.. manaleh aku compete ngan sumayy.. dia memang dedicated researcher.. live in research world! hehe..
Since I already realized that taufiq is a good role model, I need to catch up with you Mr taufiq.
BTW, thanks to all especially my beloved wife. I'll work harder and harder.
Post a Comment