在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
到目前为止,我遇到过的最奇怪的功能是BASIC方言中的“RETURN n”语句(不记得是哪一种了,这是大约28年前的事了)。“n”是可选的,默认为1。它可以是一个正数或负数,指示下一个执行的是与调用GOSUB相关的哪一行。
例如,下面将输出“30”:
10 GOSUB 200
20 PRINT "20"
30 PRINT "30"
100 END
200 RETURN +2
当我必须把一个用这种奇怪的BASIC语言编写的程序翻译成FORTRAN时,我遇到了这个问题。BASIC程序相当多地使用了这个特性,根据不同的条件返回不同的语句,我花了一段时间来理解逻辑流。一旦我理解了它,我就可以编写一个更简单的程序版本。不用说,更简单的FORTRAN版本比原来的BASIC程序bug更少。
其他回答
这缺少了一个奇怪的特性:Python没有switch语句(尽管存在变通方法)。
在Common Lisp中,零维数组是很奇怪的,而且很自然地,它们具有读取语法。
? (aref #0A5)
5
INTERCAL可能是最奇怪的语言特征的最佳汇编。我个人最喜欢的是COMEFROM语句,它(几乎)与GOTO相反。
COMEFROM is roughly the opposite of GOTO in that it can take the execution state from any arbitrary point in code to a COMEFROM statement. The point in code where the state transfer happens is usually given as a parameter to COMEFROM. Whether the transfer happens before or after the instruction at the specified transfer point depends on the language used. Depending on the language used, multiple COMEFROMs referencing the same departure point may be invalid, be non-deterministic, be executed in some sort of defined priority, or even induce parallel or otherwise concurrent execution as seen in Threaded Intercal. A simple example of a "COMEFROM x" statement is a label x (which does not need to be physically located anywhere near its corresponding COMEFROM) that acts as a "trap door". When code execution reaches the label, control gets passed to the statement following the COMEFROM. The effect of this is primarily to make debugging (and understanding the control flow of the program) extremely difficult, since there is no indication near the label that control will mysteriously jump to another point of the program.
Java;使所有对象实例都是互斥对象。
Python的everything-is-really-a-reference有一个有趣的副作用:
>>> a = [[1]] * 7
>>> a
[[1], [1], [1], [1], [1], [1], [1]]
>>> a[0][0] = 2
>>> a
[[2], [2], [2], [2], [2], [2], [2]]