Idiomatically determine all the characters that can be used for symbols: Difference between revisions
Content deleted Content added
→{{header|Tcl}}: Output limited to first 256 characters as previous output size was preventing this page from displaying properly |
Added Kotlin |
||
Line 198: | Line 198: | ||
<lang jq>count("S"; 0; 1114112)</lang> |
<lang jq>count("S"; 0; 1114112)</lang> |
||
The result is 3958. |
The result is 3958. |
||
=={{header|Kotlin}}== |
|||
{{trans|Java}} |
|||
According to the Kotlin grammar, the rules regarding which characters can appear in symbols (or identifiers as we usually call them) are the same as in Java, namely: |
|||
1. An identifier is a sequence of any number of unicode letters or digits, other than a reserved word. |
|||
2. Identifiers are case sensitive. |
|||
3. The first character must be a letter, an underscore or a $ sign. Subsequent characters can include digits and certain control characters as well though the latter are ignored for identifier matching purposes. |
|||
However, in practice, identifiers which include a $ symbol or control characters don't compile unless (in the case of $) the entire identifier is enclosed in back-ticks. The use of this device also allows one to use a reserved word or many otherwise prohibited unicode characters in an identifier including spaces and dashes. |
|||
A Kotlin label name is a valid identifier followed by an @ symbol and an annotation name is an identifier preceded by an @ symbol. |
|||
<lang scala>// version 1.1.4-3 |
|||
typealias CharPredicate = (Char) -> Boolean |
|||
fun printChars(msg: String, start: Int, end: Int, limit: Int, p: CharPredicate, asInt: Boolean) { |
|||
print(msg) |
|||
(start until end).map { it.toChar() } |
|||
.filter { p(it) } |
|||
.take(limit) |
|||
.forEach { print(if (asInt) "[${it.toInt()}]" else it) } |
|||
println("...") |
|||
} |
|||
fun main(args: Array<String>) { |
|||
printChars("Kotlin Identifier start: ", 0, 0x10FFFF, 72, |
|||
Char::isJavaIdentifierStart, false) |
|||
printChars("Kotlin Identifier part: ", 0, 0x10FFFF, 25, |
|||
Character::isJavaIdentifierPart, true) |
|||
printChars("Kotlin Identifier ignorable: ", 0, 0x10FFFF, 25, |
|||
Character::isIdentifierIgnorable, true) |
|||
}</lang> |
|||
{{out}} |
|||
<pre> |
|||
Kotlin Identifier start: $ABCDEFGHIJKLMNOPQRSTUVWXYZ_abcdefghijklmnopqrstuvwxyz¢£¤¥ªµºÀÁÂÃÄÅÆÇÈÉÊ... |
|||
Kotlin Identifier part: [0][1][2][3][4][5][6][7][8][14][15][16][17][18][19][20][21][22][23][24][25][26][27][36][48]... |
|||
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|ooRexx}}== |
=={{header|ooRexx}}== |