Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Invalid command name ""

189 views
Skip to first unread message

jazz...@gmail.com

unread,
Jul 29, 2005, 4:06:44 PM7/29/05
to
Hi,
I'm trying to expand the capabilities of the Android testing tool,
http://www.wildopensource.com/activities/larry-projects/android.php.
I'm not familiar with Tcl, but I've been learning along the way. This
if statement :

if { [ check_for_dbl_click $click_line $click_text ] } {
set fnd_dbl_clk 1
[ transform_line $click_line ]
}

causes Tcl to complain : invalid command name "". Those are empty
quotes. What does this mean? Before I put in the set line, I could
write the test and command on one line and the Tcl parser would be
happy. I've tried rewriting this line a few times to try to remove any
extraneous spaces, but I can't seem to satisfy it. It complains
spefically about the [ transform_line $click_line ] statement. What am
I missing?

Thanks,

Jason Mazzotta

jazz...@gmail.com

unread,
Jul 29, 2005, 4:23:30 PM7/29/05
to
With more experimentation, I found the answer. I guess, I still don't
completely understand the role of the square brackets. If I remove
those, Tcl is happy. Can someone tell me why those []'s shouldn't be
there?


Thanks,


Jason Mazzotta

Ahran

unread,
Jul 29, 2005, 4:36:29 PM7/29/05
to
Square brackets tell tcl to do an evaluation in line and substitute the
results in place. Tcl evaluates each command in 2 steps so the first
step executes what's inside the square brackets and the second step
fails because it expects a valid tcl command and instead finds "" (the
result of the first command).

You'd typically use square brackets when you'd want to capture the
result of a command and do something with it later on or in and if
statement (like you see in your example) to test the results of a
command.

set result [transform_line $click_line]
if { $result != "" } {
puts "I didn't expect anything but instead I got \"$result\""
}

The Tcl man page has a decent description of this.
http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm#M6
http://www.tcl.tk/man/tcl8.4/TclCmd/Tcl.htm#M10

-Ahran

Aric Bills

unread,
Jul 29, 2005, 5:09:14 PM7/29/05
to
Square brackets tell the parser to perform "command substitution"--Tcl's
way of nesting function calls.

If you're familiar with C, imagine that you have two functions, "double"
and "triple". Each takes an integer and returns an integer. Assuming
you had a variable "num" of type integer, you could do:

num = double(triple(6));

In Tcl, this would be:

set num [double [triple 6]]

(Note that "set", like "double" and "triple" is a command--but it's not
in brackets because it's the outermost command, i.e. not nested.)

When the parser hits an expression in square brackets, it evaluates
what's inside the brackets and substitutes the result into the script as
a single "word" or argument. In the case of your code, the result was
an empty string, which Tcl tried to evaluate as a command because it was
the first non-whitespace word on the line.

Here are some more examples of appropriate use of square brackets:

# example 1
set answer [expr {5 + 5}]


# example 2
proc num {} {
return 5
}

set answer [expr {[num] + 5}]


# example 3
set words [list some words to be sorted]
set first_word [lindex [lsort $words] 0]

It looks like Ahran has pointed you to the "endekalogue"--the Tcl man
page. Depending on whether you're using version 8.5 of Tcl or a
previous version, Tcl has only 12 or 11 syntax rules, of which command
substitution is one. Since there are so few rules and since each one is
quite important, it's a good idea to familiarize yourself with them.
Wrapping your mind around the simplicity (and rigidity) of Tcl's syntax
can be tricky if you're used to languages like C, where the parser does
a lot more work. Once you're used to it, though, you will love being
able to look at a program and know exactly how the interpreter is going
to parse it.

Regards,
Aric

By the way, it is possible to define a Tcl procedure whose name is the
empty string. Probably not a good idea, but if you had had one in your
program, Tcl would have executed it as the result of [ transform_line
$click_line ].

proc "" {} {
puts "this is the empty string proc"
}

From an interactive Tcl shell:

% ""
this is the empty string proc
% {}
this is the empty string proc

Gerald W. Lester

unread,
Jul 29, 2005, 5:21:59 PM7/29/05
to

My guess is that transform_line returns an empty string instead of a valid
command name.

In Tcl the first word on a "line" is the command, in this case the first
word is the value returned by transform_line (square brackets roughly mean
evaluate what is in side of the square brackets as a command and its
arguments and substitute the return value of the command in place of the
square brackets and its contents).

Thus in the above if the value of click_line is foo and the "line" is: [
transform_line $click_line ]
The parser sees the square brackets, pauses execution and evaluates
transform_line $click_line
it sees the the $click_line, substitiutes its value, thus giving
transform_line foo
it then call transform_line with one argument, foo. Let us say it returns
the null string. The parser will then resume the suspended execution os
the original line, substituing in "" for square brackets and its contents.
Thus it attempts to evaluate:
""

From the error message, it would appear you do not have a procedure whose
name is the null string.


--
+--------------------------------+---------------------------------------+
| Gerald W. Lester | "The man who fights for his ideals is |
| Gerald...@cox.net | the man who is alive." -- Cervantes |
+--------------------------------+---------------------------------------+

sleb...@gmail.com

unread,
Jul 29, 2005, 8:05:43 PM7/29/05
to
All above explanations are correct. To understand this, try the
following:

proc testproc {} {
return "This is a test"
}

proc squareproc {} {
return "testproc"
}

[ squareproc ]

The function squareproc in my example just return the string testproc.
Note that it is just a string and squareproc does nothing special.
The interpreter will execute the first word of a line. Since squareproc
returns the word testproc then testproc becomes the first word on the
line.

Michael A. Cleverly

unread,
Jul 29, 2005, 9:02:07 PM7/29/05
to
On Fri, 29 Jul 2005, Aric Bills wrote:

> By the way, it is possible to define a Tcl procedure whose name is the empty
> string. Probably not a good idea,

I use this idiom with tdom fairly regularly. It allows me to write
something like:

[[$node selectNodes $xpath] someMethod]

where $xpath is an xpath expression that might return 0 or 1 nodes. To
avoid having to explicitly deal with the case where no nodes would be
returned I define:

proc "" args {}

Michael

Aric Bills

unread,
Jul 30, 2005, 2:44:15 PM7/30/05
to
I stand enlightened. Thanks for sharing :)

jazz...@gmail.com

unread,
Aug 2, 2005, 12:25:19 PM8/2/05
to
Thanks for all the explanation. I'll look at those Tcl links. They
should come in handy as I use this tool more.


Jason Mazzotta

Jayashree Peluri

unread,
Nov 7, 2022, 10:40:28 PM11/7/22
to
I tried using the proc "" args {}
Now I don't see any error, but this function is breaking the flow of my program. Should I place any statment that continues the execution? I tried return "none" but of no use.

Rich

unread,
Nov 7, 2022, 10:48:56 PM11/7/22
to
Wow, resurrecting a 17 year old thread.....

Please explain how "this function is breaking the flow of my program".
That statement makes no sense.

Jayashree Peluri

unread,
Nov 8, 2022, 1:06:02 AM11/8/22
to
Sorry for waking up the dead 😅 Looks like the program restarted because of another issue. Resolved it now!
I confirm this 'proc "" args {} ' is working wonders! :) Thanks for prompt reply making me reassess the error!

heinrichmartin

unread,
Nov 8, 2022, 2:12:28 AM11/8/22
to
On Tuesday, November 8, 2022 at 7:06:02 AM UTC+1, shree wrote:
> On Tuesday, November 8, 2022 at 11:48:56 AM UTC+8, Rich wrote:
Imo, the current level of divine support is unhealthy - you want more or less of it, depending on your belie...ehm requirements.

Less wonders: You are maybe covering an issue, and you are not even logging it. Is "do nothing" an expected result of transform_line?
More wonders: If transform_line may return nothing (or a command with args), then you actually want <code>{*}[transform_line ...]</code> in modern Tcl.
0 new messages