有没有一种语言的名称可以包含空格字符?

发布于 2024-10-03 03:29:14 字数 46 浏览 6 评论 0原文

是否有任何编程语言允许名称包含空格? (通过名称,我指的是变量、方法、字段等)

Is there any programming language that allows Names to include white spaces ? (By names, I intend variables, methods, field, etc.)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

奶气 2024-10-10 03:29:14

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

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):

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
碍人泪离人颜 2024-10-10 03:29:14

Common Lisp 可以用变量来做到这一点,如果你用管道 (|) 包围变量名称:

CL-USER> (setf |hello world| 42)
42
CL-USER> |hello world|
42

值得注意的是,“管道”变量名称也是区分大小写的(这些变量名称通常不在 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

Common Lisp can do it with variables, if you surround the variable name with pipes (|):

CL-USER> (setf |hello world| 42)
42
CL-USER> |hello world|
42

Worth noting is that "piped" variable names also are case sensitive (which variable names normally aren't in 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
淡紫姑娘! 2024-10-10 03:29:14

在 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".

深海少女心 2024-10-10 03:29:14

PHP 可以: http://blog.riff.org/2008_05_11_spaces_php_variable_names

Perl 还可以:

${'some var'} = 42;
print ${'some var'}, "\n";

${'my method'} = sub {
  print "method called\n";
};

&${'my method'};

PHP can: http://blog.riff.org/2008_05_11_spaces_php_variable_names

Perl also:

${'some var'} = 42;
print ${'some var'}, "\n";

${'my method'} = sub {
  print "method called\n";
};

&${'my method'};
凤舞天涯 2024-10-10 03:29:14

JavaScript 的最新创新和实验性 Web 脚本(子)类型: https://github.com/featurist /pogoscript/wiki

wind speed = 25
average temperature = 32

成为

windSpeed = 25
averageTemperature = 32

屏幕后面。关于返回变量的定位也有灵活的规则,这样你就可以:

y = compute some value from (z) and return it
md5 hash (read all text from file "sample.txt")

变成:

var y;
y = computeSomeValueFromAndReturnIt(z);
md5Hash(readAllTextFromFile("sample.txt"));

A more recent innovation and experimental web script (sub)type of JavaScript: https://github.com/featurist/pogoscript/wiki

wind speed = 25
average temperature = 32

becomes

windSpeed = 25
averageTemperature = 32

Behind the screens. Also flexible rules on positioning of return variables so you can do:

y = compute some value from (z) and return it
md5 hash (read all text from file "sample.txt")

Becomes:

var y;
y = computeSomeValueFromAndReturnIt(z);
md5Hash(readAllTextFromFile("sample.txt"));
暖心男生 2024-10-10 03:29:14

在 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.

云归处 2024-10-10 03:29:14

变量名中空格的问题在于它需要解释,因为空格通常意味着“好的,当前标记结束,开始另一个标记”。此规则的例外必须有一些特殊的指示符,例如字符串中的引号(“这是一个测试”)。

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").

も星光 2024-10-10 03:29:14

我们的 PARLANSE 并行编程语言就是其中之一。事实上,它允许标识符中的任何字符,尽管其中许多字符(包括空格)必须经过转义(前面带有 ~)才能包含在名称中。这是一个例子:

         ~'Buffer~ Marker~'

这用于让 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:

         ~'Buffer~ Marker~'

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.

酒废 2024-10-10 03:29:14

您也许可以在此网站上找到不使用空格分隔表达式元素的深奥语言: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

千纸鹤带着心事 2024-10-10 03:29:14

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".

土豪我们做朋友吧 2024-10-10 03:29:14

创建此类支持标识符中空格的语言应该不会有太大问题,只要有足够的分隔标记来说明解析器标识符的结尾(例如运算符、大括号、逗号和臭名昭著的分号)。它只是并没有太大地提高源代码的可读性。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文