Unicode variable names
- 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.
- Show how to:
- Set a variable with a name including the 'Δ', (delta character), to 1
- Increment it
- Then print its value.
Go
Go source encoding is specified to be UTF-8. Allowable variable names are specified in the sections identifiers and Exported identifiers. <lang go>package main
import "fmt"
func main() {
Δ := 1 Δ++ fmt.Println(Δ)
}</lang> Output:
2
Perl6
Perl 6 is written in Unicode so, with narrow restrictions, nearly any Unicode letter can be used in identifiers.
See Perl 6 Synopsis 02. - http://perlcabal.org/syn/S02.html#Names
<lang perl6>my $Δ = 1; $Δ++; say $Δ;</lang>
Function and subroutine names can also use Unicode characters: (as can methods, classes, packages, whatever...)
<lang perl6>my @ᐁ = (0, 45, 60, 90);
sub π { pi };
sub postfix:<°>($degrees) { $degrees * π / 180 };
for @ᐁ -> $ಠ_ಠ { say sin $ಠ_ಠ° };</lang>
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.