Jump to content

Idiomatically determine all the characters that can be used for symbols: Difference between revisions

(Added XPL0 example.)
Line 328:
Kotlin Identifier ignorable: [0][1][2][3][4][5][6][7][8][14][15][16][17][18][19][20][21][22][23][24][25][26][27][127][128]...
</pre>
 
=={{header|Nim}}==
As regards identifiers, there exists a general rule which describes how they can be formed. For this rule, the following program prints the allowed starting characters and the allowed characters:
 
<lang Nim>import sequtils, strutils
 
echo "Allowed starting characters for identifiers:"
echo toSeq(IdentStartChars).join()
echo ""
echo "Allowed characters in identifiers:"
echo toSeq(IdentChars).join()</lang>
 
{{out}}
<pre>Allowed starting characters for identifiers:
ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz
 
Allowed characters in identifiers:
0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz</pre>
 
But Nim is a lot more flexible and allows using Unicode symbols in identifiers provided these are letters and digits. Thus, the following program is valid:
 
<lang Nim>var à⁷ = 3
echo à⁷</lang>
 
Using escape character <code>`</code>, it is possible to override the rules and to include any character in an identifier and even to use a keyword as identifier. Here is an example of the possibilities:
 
<lang Nim>var `const`= 3
echo `const`
 
proc `<`(a, b: int): bool =
echo a, " ", b
system.`<`(a, b)
 
echo 4 < 7
 
proc `Π`(a: varargs[int]): int =
result = 1
for n in a: result *= n
 
echo Π(4, 5, 7)
 
var `1` = 2
echo `1`
</lang>
 
=={{header|Ol}}==
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.