:TITLE: Evaluation & Substitutions 2: Grouping arguments with {} ;# ;# RCSID: $Header: /cvsroot/tcl/tcltutorial/original/Tcl4.lsn,v 1.1 2004/11/04 16:01:14 davidw Exp $ ;# Copyright (c) 1995 Clif Flynt ;# 9300 Fleming Rd. ;# Dexter, MI 48130 ;# clif@cflynt.com ;# See file "NOTICE" for licensing terms. ;# :LESSON_TEXT_START_LEVEL 0: During the substitution phase of command evaluation, the two grouping operators, the brace ({) and the double quote ("), are treated differently by the Tcl interpreter.
Grouping a set of words within braces disables all of the substitutions that can occur within a set of words grouped by quotes. The characters within braces are passed to a command exactly as they are written.
The only "Backslash Sequence" that is processed within braces is the backslash at the end of a line. This is still a line continuation character.
If you haven't hit the Run Example button yet, do so now, and examine the results of the example. Play around a bit with the example code, and then go on to the next lesson. :TEXT_END: :LESSON_TEXT_START_LEVEL 1: During the substitution phase of command evaluation, the two grouping operators, the brace ({) and the double quote ("), are treated differently by the Tcl interpreter.
In the last lesson you saw that grouping words with double quotes allows substitutions to occur within the double quotes. By contrast, grouping words within double braces *disables* substitution within the braces. Characters within braces are passed to a command exactly as written. The only "Backslash Sequence" that is processed within braces is the backslash at the end of a line. This is still a line continuation character.
Note that braces have this effect only when they are used as a grouping operator. If a string is already grouped, either with quotes or braces, and braces occur within the grouped string, then the braces are treated as ASCII characters. If the string is grouped with quotes, substitutions will occur within the quoted string, even between the braces.
If you haven't hit the Run Example button yet, do so now, and examine the results of the example. Play around a bit with the example code, and then go on to the next lesson.
:TEXT_END:
:LESSON_TEXT_START_LEVEL 2: In the last lesson, you learned that both double quotes ("") and braces ({}) can be used to group a set of words into a single unit. However, these two grouping operators do not behave the same during the substitution phase of command evaluation.
Where double quotes allow substitutions to occur within the quoted string, braces *disable* substitution. The set of words grouped by the braces is evaluated exactly as written. For example, the string
{$variableName}
will be passed to a command as
$variableName
and no substitution will occur. The only "Backslash
Sequence" that is processed within braces is the
backslash at the end of a line. This will still cause
two lines to be evaluated as though there were no
newline after the backslash.
Note that braces have this effect only when they are used as a grouping operator. If a string is already grouped, either with quotes or braces, and braces occur within the grouped string, then the braces are treated as ASCII characters. If the string is grouped with quotes, substitutions will occur within the quoted string, even between the braces.
If you haven't hit the Run Example button yet, do so now, and examine the results of the example. Play around a bit with the example code, and then go on to the next lesson. :TEXT_END: :CODE_START: set Z "Albany" set Z_LABEL "The Capitol of New York is: " puts "\n................. examples of differences between \" and \{" puts "$Z_LABEL $Z" puts {$Z_LABEL $Z} puts "\n....... examples of differences in nesting \{ and \" " puts "$Z_LABEL {$Z}" puts {Who said, "What this country needs is a good $0.05 cigar!"?} puts "\n................. examples of escape strings" puts {There are no substitutions done within braces \n \r \x0a \f \v} puts {But, the escaped newline at the end of a\ string is still evaluated as a space} :TEXT_END: