Unicode variable names: Difference between revisions

From Rosetta Code
Content added Content deleted
(omissions)
(→‎Tcl: Added description)
Line 31: Line 31:
2
2
>>> </lang>
>>> </lang>

=={{header|Tcl}}==
Tcl variable names can include any character (the <code>$var</code> syntax can't, but that's just a shorthand). Thus, this script is entirely legal:
<lang tcl>set Δx 1
incr Δx
puts [set Δ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.


{{omit from|AWK}}
{{omit from|AWK}}

Revision as of 16:21, 2 July 2011

Unicode variable names is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.
  1. Describe, and give a pointer to documentation on your languages use of characters beyond those of the ASCII character set in the naming of variables.
  2. Show how to:
  • Set a variable with a name including the 'Δ', (delta character), to 1
  • Increment it
  • Then print its value.

Protium

1. (working on it)

2. <lang protium><@ LETVARLIT>Δ|1</@> <@ ACTICRVAR>Δ</@> <@ SAYVAR>Δ</@></lang>

Using what Google Translate says is the Traditional Chinese for 'delta' <lang protium><@ LETVARLIT>三角洲|1</@> <@ ACTICRVAR>三角洲</@> <@ SAYVAR>三角洲</@></lang>

Python

Within the ASCII range (U+0001..U+007F), the valid characters for identifiers are the same as in Python 2.x: the uppercase and lowercase letters A through Z, the underscore _ and, except for the first character, the digits 0 through 9.

Python 3.0 introduces additional characters from outside the ASCII range (see PEP 3131). For these characters, the classification uses the version of the Unicode Character Database as included in the unicodedata module.

Identifiers are unlimited in length. Case is significant.

<lang python>>>> Δx = 1 >>> Δx += 1 >>> print(Δx) 2 >>> </lang>

Tcl

Tcl variable names can include any character (the $var syntax can't, but that's just a shorthand). Thus, this script is entirely legal: <lang tcl>set Δx 1 incr Δx puts [set Δx]</lang> However, this script only works smoothly if the “Δ” 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.