tags:

views:

97

answers:

5

Hi all,

I am learning TCL and wanted to know how can I find out errors in my code. I mean what line no is error happening or how can I debug it.

Following is the code which I am trying :

proc ldelete {list value}{
    set ix [lsearch -exact $list $value]
    if{$ix >=0}{
        return [lreplace $list $ix $ix]
    } else {
        return $list
    }
}

Following is the error i am getting :

 extra characters after close-brace

I will appreciate the help.

Thanks aditya

+1  A: 

You need a space here

proc ldelete {list value}{

proc ldelete {list value} {

and here

if{$ix >=0}{

if{$ix >=0} {

Byron Whitlock
Also a space between `if` and the condition.
Donal Fellows
+2  A: 

If you are running this thus:

tcl foo.tcl

then you should be getting an error message telling you that the error is on line 1. (The problem is the lack of a space between the close brace and the open brace.)

As a general rule, if you are working interactively, useful messages (eg the stack trace) are often found in errorInfo, so this is often helpful:

% puts $errorInfo

Eric Neilsen
A: 

I use a static checker called 'frink'. Google for it and you will find it.

UPDATE: Yes, frink finds many errors I missed. Give me a try.

Hai Vu
hi VuThanks for your suggestion but do you use frink to find out errors in TCL
Adi
A: 

Try looking at the contents of the global variable errorInfo

puts $::errorInfo

Relevant documentation links: http://www.tcl.tk/man/tcl8.5/TclCmd/return.htm and http://wiki.tcl.tk/1645

Trey Jackson
+1  A: 

If you purchase a copy of the Tcl Dev Kit sold by ActiveState, it includes a tool called "tclchecker" which checks for many different kinds of possible problems.

A free alternative, besides frink, is a tool called nagelfar. It provides a variety of static checks.

lvirden