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

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


当前回答

Forth可以随时改变数字的基数:

HEX 10 DECIMAL 16 - .
0 Ok

它也不需要是预定义的:

36 BASE ! 1Z DECIMAL .
71 Ok

其他回答

我在试图找出一个完全没有意义但无论如何都能工作的MACRO时遇到了这个。这对于objective-c是正确的,但对于其他类型的C(或者至少是gcc编译器)也可能是正确的。

NSString *oneString = @"This " @"is " @"just " @"one " @"normal " @" string";

=

NSString *oneString = @"This is just one normal string";

C风格的字符串也是如此

char* str = "this " "also " "works";

我有点纠结:

1;

在perl中,模块需要返回true。

PHP对字符串中数值的处理。详见之前对另一个问题的回答,但简而言之:

"01a4" != "001a4"

如果你有两个包含不同数量字符的字符串,它们不能被认为是相等的。前导零很重要,因为它们是字符串而不是数字。

"01e4" == "001e4"

PHP doesn’t like strings. It’s looking for any excuse it can find to treat your values as numbers. Change the hexadecimal characters in those strings slightly and suddenly PHP decides that these aren’t strings any more, they are numbers in scientific notation (PHP doesn’t care that you used quotes) and they are equivalent because leading zeros are ignored for numbers. To reinforce this point you will find that PHP also evaluates "01e4" == "10000" as true because these are numbers with equivalent values. This is documented behaviour, it’s just not very sensible.

我曾经写过一种编程语言,它有一个“strfry”操作符:

"hello world"?
# => "wdo rlholle"

有用的,是吗?

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