Fine Points - Newport XPS-Q8 Manual

Universal high-performance motion controller/driver
Table of Contents

Advertisement

XPS-Q8
Grouping decisions
the values of variables or command results do not affect grouping.
sign, $, causes variable substitution. Variable names can be any length, and
• A
dollar
are sensitive to case used. If variable references are embedded into other strings, or
if they include characters other than letters, digits, and the underscore, they can be
distinguished with the ${varname} syntax.
• Square brackets,
brackets is treated as a command, and everything including the brackets is replaced
with the result of the command. Nesting is allowed.
• The
backslash
as another form of substitution in which the backslash and the next character or
group of characters is replaced with a new character.
Substitutions
a group can be a constant string, and other parts can be the result of substitutions.
Even the command name can be affected by substitutions.
• A single round of substitutions is performed before a command is invoked. The
result of a substitution is not interpreted a second time. This rule is important if you
have a variable value or a command result that contains special characters such as
spaces, dollar signs, square brackets, or braces. Because only a single round of
substitution is done, you do not have to worry about special characters in values
causing extra substitutions.
2.2.13

Fine Points

• A common error is to forget a space between arguments when grouping with braces
or quotes. This is because white space is used as the separator, while the braces or
quotes only provide grouping. If you forget the space, you will get syntax errors about
unexpected characters after the closing brace or quote. The following is an error because
of the missing space between } and {:
if
{$x >
1}{puts
• A double quote is only used for grouping when it comes after white space. This
means you can include a double quote in the middle of a group without quoting it
with a backslash. This requires that curly braces or white space delimit the group.
Using this obscure feature is not recommended, but this is what it looks like:
set
silly a"b
• When double quotes are used for grouping, the special effect of curly braces is
turned off. Substitutions occur everywhere inside a group formed with double
quotes.
set
x xvalue
set
y
"foo {$x} bar"
⇒ foo {xvalue} bar
• When double quotes are used for grouping and a nested command is encountered,
the nested command can use double quotes for grouping, also.
puts
"results [format
• Spaces are not
substitution. For the purposes of grouping, the interpreter considers everything
between the square brackets as part of the current group. The following sets x to the
concatenation of two command results because there is no space between ] and [.
set
x [cmd1][cmd2]
• Newlines and semicolons are ignored when grouping with braces or double quotes.
They get included in the group of characters just like all the others. The following
sets x to a string that contains newlines:
set
x "This is line one.
are made before substitutions are performed, which means that
[
], cause command substitution. Everything between the
character, \, is used to quote special characters. You can think of this
can occur anywhere unless prevented by curly brace grouping. Part of
"x =
$x"}
"%f
%f" $x $y]"
required around the square brackets used for command
13
Tcl Manual
EDH0307En1041 — 10/17

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents