Adi
Adi

Reputation: 1639

How to find error in TCL code

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

Upvotes: 0

Views: 4782

Answers (5)

lvirden
lvirden

Reputation: 56

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.

Upvotes: 1

Hai Vu
Hai Vu

Reputation: 40688

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.

Upvotes: 0

Trey Jackson
Trey Jackson

Reputation: 74420

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

Upvotes: 1

EHN
EHN

Reputation: 618

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

Upvotes: 5

Byron Whitlock
Byron Whitlock

Reputation: 53850

You need a space here

proc ldelete {list value}{

proc ldelete {list value} {

and here

if{$ix >=0}{

if{$ix >=0} {

Upvotes: 1

Related Questions