Identifiers Characters
来源:互联网 发布:mac terminal 指令 编辑:程序博客网 时间:2024/06/08 11:08
What characters can you use in identifiers?
Here is a summary of the rules for identifiers, used for method and type names, variables, etc:
- Characters
Scala allows all the printable ASCII characters, such as letters, digits, the underscore_
, and the dollar sign$
, with the exceptions of the “parenthetical” characters,(
,)
,[
,]
,{
, and}
, and the “delimiter” characters, ’(backticks倒引号)'
"
.
;
and,
. Scala allows the other characters between\u0020
and\u007F
that are not in the sets just shown, such as mathematical symbols, the so-called operator characters like/
and<
, and some other symbols. - Reserved words can’t be used
As in most languages, you can’t reuse reserved words for identifiers.
Reserved words lists Plain identifiers—combinations of letters, digits,
$
,_
, and operators
A plain identifier can begin with a letter or underscore, followed by more letters, digits, underscores, and dollar signs. Unicode-equivalent characters are also allowed.Scala reserves the dollar sign for internal use, so you shouldn’t use it in your own identifiers, although this isn’t prevented by the compiler.
After an underscore, you can have either letters and digits, or a sequence of operator characters. The underscore is important. It tells the compiler to treat all the characters up to the next whitespace as part of the identifier. For example,
val xyz_++= = 1
assigns the variablexyz_++=
the value1
, while the expressionval xyz++= = 1
won’t compile because the “identifier” could also be interpreted asxyz ++=
, which looks like an attempt to append something toxyz
. Similarly, if you have operator characters after the underscore, you can’t mix them with letters and digits. This restriction prevents ambiguous expressions like this:abc_-123
. Is that an identifierabc_-123
or an attempt to subtract123
fromabc_
?- Plain identifiers—operators
If an identifier begins with an operator character, the rest of the characters must be operator characters. “Back-quote” literals
An identifier can also be an arbitrary string between two back quote characters, e.g.,def `test that addition works` = assert(1 + 1 == 2).
- Pattern-matching identifiers
In pattern-matching expressions , tokens that begin with a lowercase letter are parsed as variable identifiers, while tokens that begin with an uppercase letter are parsed as constant identifiers (such as class names). This restriction prevents some ambiguities because of the very succinct variable syntax that is used, e.g., noval
keyword is present.
Ref
《Programming Scala》
- Identifiers Characters
- Identifiers
- Non-ASCII characters are not allowed outside of literals and identifiers
- Using Identifiers
- Language Identifiers
- [ACM]Identifiers
- sdut2163 Identifiers
- Company Identifiers
- C identifiers
- Identifiers:标识符
- characters
- 9.4.2 Identifiers
- IE program - Command Identifiers
- IE program - Command Identifiers
- Stream Unique Identifiers
- View context menu identifiers
- Code Page Identifiers zz
- Code Page Identifiers
- 二叉树的递归创建和遍历
- 数据结构(5)—— 链表、二叉树代码重构实现
- verilog-不可综合语句-总结-汇总
- opencv3.0学习笔记【10/8】
- 逆序数
- Identifiers Characters
- 不容错过这十款 GNOME Shell 扩展
- Spring 配置使用 - Bean 生命周期
- javascript复习(关于判断)
- 音乐播放器Service和Activity交互实践
- 直播技术框架
- java web 分页实现
- matlab 雅可比矩阵求取
- DOS常用命令