有没有一种语言的名称可以包含空格字符?
是否有任何编程语言允许名称包含空格? (通过名称,我指的是变量、方法、字段等)
Is there any programming language that allows Names to include white spaces ? (By names, I intend variables, methods, field, etc.)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
Scala 确实允许在标识符名称中使用空格字符(但要实现这一点,您需要用一对反引号将标识符括起来)。
示例(在 Scala REPL 中执行):
Scala does allow whitespace characters in identifier names (but for that to be possible, you need to surround the identifiers with pair of backticks).
Example (executed at Scala REPL):
Common Lisp 可以用变量来做到这一点,如果你用管道 (|) 包围变量名称:
值得注意的是,“管道”变量名称也是区分大小写的(这些变量名称通常不在 CL 中)。
Common Lisp can do it with variables, if you surround the variable name with pipes (|):
Worth noting is that "piped" variable names also are case sensitive (which variable names normally aren't in CL).
在 SQL 中,字段名称等中可以包含空格和其他非标识符字符。您只需引用它们,例如
[field name]
或"field name"
。In SQL you can have spaces and other non-identifier characters in field names and such. You just have to quote them like
[field name]
or"field name"
.PHP 可以: http://blog.riff.org/2008_05_11_spaces_php_variable_names
Perl 还可以:
PHP can: http://blog.riff.org/2008_05_11_spaces_php_variable_names
Perl also:
JavaScript 的最新创新和实验性 Web 脚本(子)类型: https://github.com/featurist /pogoscript/wiki
成为
屏幕后面。关于返回变量的定位也有灵活的规则,这样你就可以:
变成:
A more recent innovation and experimental web script (sub)type of JavaScript: https://github.com/featurist/pogoscript/wiki
becomes
Behind the screens. Also flexible rules on positioning of return variables so you can do:
Becomes:
在 Ruby 中,您可以拥有名为
:"this has a space"
的符号,但它用双引号括起来,所以我不确定您是否算在内。如果其他语言允许空格作为符号名称中的有效字符,那么您将必须使用其他字符来分隔它们。
In Ruby you can have symbols that are named as
:"this has a space"
but it is enclosed in double-quotes so I'm not sure if you count that.If other languages allowed whitespace as a valid character in symbol names, then you would have to use some other character to separate them.
变量名中空格的问题在于它需要解释,因为空格通常意味着“好的,当前标记结束,开始另一个标记”。此规则的例外必须有一些特殊的指示符,例如字符串中的引号(“这是一个测试”)。
The problem with spaces in variable names is that it's subject to interpretation since whitespace normally means "ok, end of the current token, starting another." Exceptions to this rule must have some special indicator such as quotation marks in a string ("This is a test").
我们的 PARLANSE 并行编程语言就是其中之一。事实上,它允许标识符中的任何字符,尽管其中许多字符(包括空格)必须经过转义(前面带有 ~)才能包含在名称中。这是一个例子:
这用于让 PARLANSE 轻松引用来自其他语言的任意符号(特别是从任意参考文档中获取的 EBNF,我们无法控制所使用的标点符号)。
我们不经常使用此功能,但是当需要时,这意味着我们可以忠实于其他文档中的标记。
Our PARLANSE parallel programming language is one such. In fact, it allows any character in identifiers, although many of them, including spaces, have to be escaped (preceded by ~) to be included in the name. Here's an example:
This is used to let PARLANSE easily refer to arbitrary symbols from other languages (in particular, from EBNFs taken from arbitrary reference documents, where we can't control the punctuation used).
We don't use this feature a lot, but when it is needed it means we can stay true to tokens from other documents.
您也许可以在此网站上找到不使用空格分隔表达式元素的深奥语言:http:// 99-bottles-of-beer.net
例如...空白: D
You might be able to find esoteric languages that don't separate expression elements with whitespaces on this website: http://99-bottles-of-beer.net
For example... whitespace :D
SQL 的某些方言允许数据库、表和字段的名称中包含空格。
例如,在 SQL Server 中,您可以通过将表名放在
[方括号]
中或(取决于连接选项)放在" 中来引用名称中带有空格的表。双引号”
。Some dialects of SQL allow databases, tables, and fields to have spaces in their names.
For example, in SQL Server, you can refer to a table with a space in its name, either by putting the table name in
[square brackets]
or (depending on connection options) in"double quotes"
.创建此类支持标识符中空格的语言应该不会有太大问题,只要有足够的分隔标记来说明解析器标识符的结尾(例如运算符、大括号、逗号和臭名昭著的分号)。它只是并没有太大地提高源代码的可读性。
There shouldn't be much problems creating such languages supporting whitespaces in identifiers, as long as there are enough separating tokens which say the parser where the identifiers end (such as operators, braces, commas and the infamous semicolon). It just doesn't improve the readability of the source code much.