| |||||||||||
| |||||||||||
Curley brackets v double quotes - Tcl, Tk, Expect
In Tcl, both Curley braces and double quotes can be used to hold a block of program or data together as a single unit / parameter ... but there are differences ...
a) Curley braces can stretch over a number of lines, with new lines within the block being simply a part of the block. So they're ideal for defining blocks of code b) Curley braces can be nested - since there are different open and close characters, blocks within blocks are written easily and naturally, which is quite impractical with double quotes! c) the biggest difference is that double quoted blocks are evaluated at the time they are encountered by the language parser, but curley braces are deferred until they are (perhaps) evaluated later under the control of the command of which they form a part. Let's see an example - I've defined two procs with identical code in the body, but one is done with braces and the other with quotes: set sample 5The first proc - demo - has a DEFERRED block which means that the $sample variable isn't evaluated until the proc is RUN. The second proc - omed - has an IMMEDIATE block which means that the $sample variable is evaluated as the proc is being DEFINED and the proc always returns "5" ... The info body command allows you to see the contents of your procs ... not a very common requirement, but wonderful for a demonstration like this one! Here it is, run ... Dorothy:dectcl grahamellis$ tclsh t2(written 2007-12-12 23:18:38) Associated topics are indexed under T248 - Tcl/Tk - A Review of Tcl and Tk BasicsT202 - Tcl/Tk - Tcl Fundamentals T211 - Tcl/Tk - What is Expect? Why use it?
Some other Articles
Making a variable dynamically visible in a Tcl/Tk GUIThe Horse goes on and on Cliff Lift simulator- Lynton to Lynmouth - in Tcl/Tk fill and expand on Tcl/Tk pack command Curley brackets v double quotes - Tcl, Tk, Expect Lexical v Arithemetic testing, Bash and Perl stdout v stderr (Tcl, Perl, Shell) Effective Java training - the bootcamp approach Perl, PHP, Python, Tcl, Linux, MySQL, Ruby courses ... Python Script - easy examples of lots of basics 1771 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36 at 50 posts per pageThis is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price. Link to Ezine home page (for reading). Link to Blogging home page (to add comments). |
| ||||||||||
PH: 0800 043 8225 or 01225 708225 • FAX: 0845 8382 405 or 01225 707126 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho | |||||||||||