I think I like the idea behind this page; but was the above babel-fished from Dutch (or Klingon)? How about some punctuation heaven?What is this 'heaven to be', and why would people be claiming it to be obnoxious or obscure?
Maybe remarks can be freely moved in between heaven or hell pages according to good public gouvernment ruling...The Main Reasons for quoting are, or have to do with, without much question:
- substitution
- evaluation
- grouping of segments of data or programs
set list {a b c} set string "a b c" set listasstring "{a b c}" ;# a string construction as a valid list set listwithstring {"a b c"} ;# a decent statement with a list containing one element: a stringDGP That forumulation is misleading. It suggests that different quoting characters have the power to give types to Tcl values. They do not. Brace-quoting doesn't make a list, and DoubleQuote-quoting doesn't make a string. This is fundamental to understanding Tcl. More truthful is:
set literalWord {a b c} set substitutedWord "a b c"The double quoted examples just amplify the confusion. Compare these:
set example1 "{a b c}" ;# your "listasstring" set example2 {{a b c}} ;# different quoting - exact same result set example3 {"a b c"} ;# different string, but same listCan't repeat it too often, the quoting chars chosen control substitution. They have zero impact on the "type" of the result, because Tcl values do not hold any "type" data.Less Obvious or Advanced Reasons for quoting probably include:
- syntax analysis
- constructing of program pieces, like in -command Tk options
- mathematical or other symbolic manipulations
- advanced list manipulation
ExamplesA simple web page generating statement using puts and clock
puts "<html>\n<h2>My Web Page</h2>\n\[clock format \[clock seconds\]\]:\n[clock format [clock seconds]]\n</html>" <html> <h2>My Web Page</h2> [clock format [clock seconds]]: Wed Oct 27 17:11:13 West-Europa (zomertijd) 2004 </html>
How about comparing quoting techniques in other scripting languages and compare and contrast the alternatives?CLN OK, I'll bite. One of the JO's greatest choices in designing Tcl was using asymetrical evaluation tokens (one to start, a different one to end). That is, whereas most UNIX shells use backquote to mean "evaluate and substitute the result here", Tcl uses [ and ]. Because the tokens are asymetrical, they can be nested. In csh, et al., you can't very well do:
x=`grep `cat somefile` *.h`because the `s don't go where you want them. But in tclsh, you can certainly do:
set x [myproc [yourproc $anArg]]Heaven! ;-)glennj To compare Tcl and Perl quoting:Tcl:
set x "hello \"$world\""Perl:
$x = "hello \"$world\""; $x = qq{hello "$world"};Tcl:
set x {an [uninterpolated $string] 'with single quotes'}Perl:
$x = 'an [uninterpolated $string] \'with single quotes\''; $x = q{an [uninterpolated $string] 'with single quotes'};In its spirit of TIMTOWDI, Perl also has here documents that can be interpolated or not.
See also Cloverfield, section Word modifiers, for an heredoc-like syntactic improvement. In short:
set s {data}MyTag some arbitrary data {\$[# MyTagYou can enclose verbatim data between arbitrary tags. One could for example choose to use the MD5 hash of the data as a tag. Combined with Critcl and tcc this can greatly simplify the integration of foreign language. We could also include raw XML data to feed tdom or TclXML with.Jim provides a similar quoting syntax:
set v {<<EOT}{ blah blah... any old stuff: $$$ {{{ [[[ \\\ ]]] etc. EOT}Meta-remark: the Wiki provides such a feature with the 6-equal marker.