Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
For 2023 (and 2024 ...) - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
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 5
 
proc demo {} {global sample; return $sample}
proc omed {} "global sample; return $sample"
 
set sample 27
 
puts "Curley braces - defer substitution until block is run"
puts [demo]
puts "Double quotes - just grouping; substition at definition time"
puts [omed]
 
puts [info body demo]
puts [info body omed]


The 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
Curley braces - defer substitution until block is run
27
Double quotes - just grouping; substition at definition time
5
global sample; return $sample
global sample; return 5
Dorothy:dectcl grahamellis$

(written 2007-12-12, updated 2007-12-13)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
T248 - Tcl/Tk - A Review of Tcl and Tk Basics
  [1092] Tcl training - often for a larger group - (2007-02-24)
  [1174] Installing Tcl and Expect on Solaris 10 - a checklist - (2007-05-02)
  [1181] Good Programming practise - where to initialise variables - (2007-05-09)
  [4208] Tcl + Tk (Wish) - an introduction and revision example - (2013-11-15)

T211 - Tcl/Tk - What is Expect? Why use it?
  [286] Automating regular manual procedures - (2005-04-21)
  [435] Expect for Windows - (2005-09-04)
  [1173] Cheat Sheet / Check list for Expect maintainers - (2007-05-02)
  [1409] What is Expect? - (2007-10-26)
  [1411] Buffering of inputs to expect, and match order - (2007-10-27)
  [1531] Expecting a item from a list of possibles - (2008-02-04)
  [1602] Automating processes through Expect - (2008-04-05)
  [2474] Using Tcl and Expect to automate repetitive jobs - (2009-10-24)
  [2489] Parallel Pinging, using Python Threads or Expect spawn lists - (2009-11-02)
  [3009] Expect in Perl - a short explanation and a practical example - (2010-10-22)
  [3286] Should we cover expect and/or Tk on our public Tcl courses? - (2011-05-11)
  [3572] Adding Expect on top of Tcl - what is it and where can I get a training course to learn about it? - (2012-01-08)
  [4405] Backup procedures - via backup server - (2015-01-24)
  [4678] Expect with Ruby - a training example to get you started - (2016-05-18)

T202 - Tcl/Tk - Tcl Fundamentals
  [3] Looking for a donkey - (2004-08-05)
  [210] Joining lists in Tcl. Indirect variables in Tcl. - (2005-02-12)
  [328] Making programs easy for any user to start - (2005-05-29)
  [349] Comments in Tcl - (2005-06-16)
  [362] The ireallyreallywanna operator - (2005-06-28)
  [782] Converting between Hex and Decimal in Tcl - (2006-06-28)
  [1136] Buffering output - why it is done and issues raised in Tcl, Perl, Python and PHP - (2007-04-06)
  [1282] Stringing together Tcl scripts - (2007-07-29)
  [1426] Buffering up in Tcl - the empty coke can comparison - (2007-11-10)
  [2442] Variable storage - Perl, Tcl and Python compared - (2009-10-08)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [4324] Learning to program - variables and constants - (2014-11-22)
  [4453] Tcl variable names - no real limits! - (2015-03-10)


Back to
Lexical v Arithemetic testing, Bash and Perl
Previous and next
or
Horse's mouth home
Forward to
fill and expand on Tcl/Tk pack command
Some other Articles
Making a variable dynamically visible in a Tcl/Tk GUI
The 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
4759 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, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This 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).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2024: 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/1469_Cur ... xpect.html • PAGE BUILT: Sun Oct 11 16:07:41 2020 • BUILD SYSTEM: JelliaJamb