在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?

请每个回答只回答一个特征。


当前回答

不知道这是不是一个功能。对一些人来说,是的,但对另一些人来说,这可能是一种令人讨厌的行为。不管怎样,我认为这是值得一提的。

在Python中,内置函数round()在Python 2x和Python 3x之间的行为略有不同。

对于Py 2x,

>>> round(0.4)
0.0
>>> round(0.5)
1.0
>>> round(0.51)
1.0
>>> round(1.5)
2.0

对于Py 3x,

>>> round(0.4)
0
>>> round(0.5)
0
>>> round(0.51)
1
>>> round(1.5)
2

我只是不熟悉Py 3x中的round()与0的工作方式。

Py 2x和Py 3x中round()的文档。

其他回答

很久以前,我曾经用BUT子句构建过一种语言。

Common Lisp的format函数有一个选项,可以将数字打印为罗马数字。

在INTERCAL中,这是你能得到的唯一输出形式。

foo是什么数据类型?

SELECT TOP 1
   NULL AS foo
INTO
   dbo.bar
FROM
   sys.columns --trivial

为什么所有东西都归零?

SELECT CAST('' AS int), CAST('' AS datetime), CAST('' AS float)

...除了这

SELECT CAST('' AS decimal)

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.

对于那些不知道的人,bc是一种“任意精度计算器语言”,我经常使用它进行快速计算,特别是当涉及的数字很大的时候($是提示符):

$ bc -lq
12^345
20774466823273785598434446955827049735727869127052322369317059031795\
19704325276892191015329301807037794598378537132233994613616420526484\
93077727371807711237016056649272805971389591721704273857856298577322\
13812114239610682963085721433938547031679267799296826048444696211521\
30457090778409728703018428147734622401526422774317612081074841839507\
864189781700150115308454681772032

bc在很长一段时间内都是标准的Unix命令。

现在是“WTF功能”。这是来自man bc(强调是我的):

quit:当读取quit语句时,bc处理器被终止, 不管在哪里找到quit语句。 例如,"if (0 == 1) quit"将导致bc终止。 halt: halt语句(扩展)是一个执行的语句 导致BC处理器仅在执行时退出。 例如,"if (0 == 1) halt"不会导致bc终止,因为停止没有执行。