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

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


当前回答

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.

其他回答

“Piet是David Morgan-Mar设计的一种深奥的编程语言,他的程序是位图,看起来像抽象艺术。”

打印Piet的程序

在Java中(这是一个导致赋值的if语句)

result = (Boolean condition) ? (if Boolean is true) : (if Boolean is false);

or

data Nat = Z|S Nat deriving Show
nattoInt Z = 0
nattoInt (S a) = 1 + nattoInt a

buildNat 0 = Z
buildNat a  =  S (buildNat (a - 1))

在Haskell…我仍然不太明白这是如何定义自然数的(我完全理解理论:-p)

我几年前使用的一个Fortran编译器有一个有趣的特性:(A)数字先存储在高字节;(b)数字按地址传递给子程序;(c)没有在编译时检查长度。

所以你可以写一个这样的程序:(如果我把语法弄乱了,请原谅。我已经很久没有写Fortran了。)

INTEGER*2 FUNCTION TIMESTWO (INTEGER*2 N)
RETURN N*2

... THEN CALL THIS SOMEWHERE WITH A LONG INTEGER ...

INTEGER*4 I, J

I=42
J=TIMESTWO(I)

J的最终值是…零!

为什么?因为传入的值是4个字节,但被调用的函数只查看前两个字节。由于前两个是0,它将0乘以2并返回它。然后将此返回值转换回四个字节。

当我第一次遇到它时,它非常神秘。几乎我传递给某些函数的每个数字都被解释为零!

在PHP中,如下:

<?php $foo = 'abc'; echo "{$foo";

是语法错误。

如果你真的想要{,后面跟着$foo的内容,你必须使用。:

<?php $foo = 'abc'; echo '{' . $foo;

在ColdFusion中,数组从1开始。