Pie*_*let 2 programming-languages compiler-theory
是否有任何编程语言允许名称包含空格?(按名称,我打算使用变量,方法,字段等)
Scala确实允许在标识符名称中使用空格字符(但为了实现这一点,您需要使用一对反引号来包围标识符).
示例(在Scala REPL上执行):
Welcome to Scala version 2.8.0.final (Java HotSpot(TM) Client VM, Java 1.6.0_22).
Type in expressions to have them evaluated.
Type :help for more information.
scala> val `lol! this works! :-D` = 4
lol! this works! :-D: Int = 4
scala> val `omg!!!` = 4
omg!!!: Int = 4
scala> `omg!!!` + `lol! this works! :-D`
res0: Int = 8
Run Code Online (Sandbox Code Playgroud)
Common Lisp 可以用变量来做,如果你用竖线 (|) 把变量名括起来:
CL-USER> (setf |hello world| 42)
42
CL-USER> |hello world|
42
Run Code Online (Sandbox Code Playgroud)
值得注意的是,“管道”变量名也区分大小写(这些变量名通常不在 CL 中)。
CL-USER> |Hello World|
The variable |Hello World| is unbound.
[Condition of type UNBOUND-VARIABLE]
CL-USER> (setf hello-world 99)
99
CL-USER> hello-world
99
CL-USER> HeLlO-WoRlD
99
Run Code Online (Sandbox Code Playgroud)