Unicode variable names: Difference between revisions

Content added Content deleted
No edit summary
Line 971: Line 971:


=={{header|Tcl}}==
=={{header|Tcl}}==
Tcl variable names can include any character <!-- but the <tt>::</tt> sequence is special — it is the namespace separator — and there are restrictions when parentheses are involved, as they are used for associative arrays; these are not matters that are in the spirit of this task though, so this is a comment! --> (the <code>$var</code> syntax can't, but that's just a shorthand for the operationally-equivalent <code>[set var]</code>). Thus, this script is entirely legal:
Tcl variable names can include any character <!-- but the <tt>::</tt> sequence is special — it is the namespace separator — and there are restrictions when parentheses are involved, as they are used for associative arrays; these are not matters that are in the spirit of this task though, so this is a comment! --> (the <code>$var</code> syntax can't, but that's just a shorthand for the operationally-equivalent <code>[set var]</code>). Also (in tcl 8.6, at least), the <code>${var}</code> syntax does work. Thus, this script is entirely legal:
<lang tcl>set Δx 1
<lang tcl>set Δx 1
incr Δx
incr Δx
puts [set Δx]</lang>
puts [set Δx]
puts ${Δx}</lang>
However, this script only works smoothly if the “<tt>Δ</tt>” character is in the system's default encoding (thankfully more common than it used to be, as more and more systems use UTF-8 or UTF-16 as their default encodings) so normal Tcl practice is to stick to ASCII for identifier names.
However, this script only works smoothly if the “<tt>Δ</tt>” character is in the system's default encoding (thankfully more common than it used to be, as more and more systems use UTF-8 or UTF-16 as their default encodings) so normal Tcl practice is to stick to ASCII for identifier names.