Comments; Substitution And Grouping Summary - Newport XPS-Q8 Manual

Universal high-performance motion controller/driver
Table of Contents

Advertisement

XPS-Q8
EDH0307En1041 — 10/17
set
x
[expr
{sqrt(2.0)}]
At this point the value of x is a double-precision floating point value, just as you would
expect. If you do this:
set
two
[expr
then you may or may not get 2.0 as the result! This is because Tcl will substitute $x
expr
and
will concatenate all its arguments into one string, and then parse the
expression again. In contrast, if you do this:
set
two
[expr
expr
then
will do the substitutions, and it will be careful to preserve the floating point
value of x. The expression will be more accurate and run more efficiently because no
string conversions will be done. The story behind Tcl values is described in more detail
in Chapter 44 on C programming and Tcl.
2.2.11

Comments

Tcl uses the pound character, #, for comments. Unlike the convention used by many
other languages, the
elsewhere is not treated as a comment. An easy trick to append a comment to the end of
a command is to precede the
# Here are some parameters
set
rate 7.0
set
months 60
One subtle effect to watch for is that a backslash effectively continues a comment line
onto the next line of the script. In addition, a semicolon inside a comment is not
significant. Only a newline terminates comments:
# Here is the start of a Tcl comment \
and some more of it; still in the comment
A surprising property of Tcl comments is that curly braces inside comments are still
counted for the purposes of finding brace pairs. This inconvenient "feature" was
probably intended to keep the original Tcl parser simple. However, this means that the
following will not work as expected:
# if {boolean expression1} {
if
{boolean expression2} {
some commands
}
The previous sequence results in an extra left curly brace, and probably a complaint
about a missing closed brace at the end of your script! A good technique to comment
out large chunks of code is to put the code inside an if block that will never execute:
if
{0} {
unused code here
}
2.2.12

Substitution and Grouping Summary

The following rules summarize the fundamental actions of grouping and substitution
that are performed by the Tcl interpreter before it invokes a command:
• Command arguments are separated by
with
curly braces
• Grouping with
interpreter includes all characters between the matching left and right brace in the
group, including newlines, semicolons, and nested braces. The enclosing (i.e.,
outermost) braces are not included in the group's value.
• Grouping with
everything until another double quote is found, including newlines and semicolons.
The enclosing quotes are not included in the group of characters. A double-quote
character can be included in the group by quoting it with a backslash, (e.g., \").
$x * $x]
{$x * $x}]
#
must occur at the beginning of a command. A
#
with a semicolon to terminate the previous command:
;# The interest rate
;# The loan term
or
double quotes
as described below.
{
}, prevents substitutions. Braces nest. The
curly
braces,
double
quotes,
"
", allows substitutions. The interpreter groups
12
white
space, unless arguments are grouped
Tcl Manual
#
that occurs

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents