开发者

How to find error in TCL code

开发者 https://www.devze.com 2023-01-03 19:19 出处:网络
I am learning TCL and wanted to know how can I find out errors in my code. I mean what lin开发者_JAVA技巧e no is error happening or how can I debug it.

I am learning TCL and wanted to know how can I find out errors in my code. I mean what lin开发者_JAVA技巧e 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


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


You need a space here

proc ldelete {list value}{

proc ldelete {list value} {

and here

if{$ix >=0}{

if{$ix >=0} {


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


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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消