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

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


当前回答

Haskell又说:

在Haskell中,你可以处理任意大小的文件,就好像它是一个简单的字符串。只有在实际使用字符串时,文件才会被读取。由于Haskell令人难以置信的懒惰,这样的程序将在恒定的空间中运行,而不管文件的大小:

main = interact (>>= \x -> if x == '\n' then "\r\n" else [x])

(这个程序将一个文件从stdin转换为stdout,并将LF替换为CRLF,交互函数将整个stdin输入到一个函数,并将输出移动到stdout。)

这种惰性也可能导致问题,因为如果关闭一个文件句柄,就不能完全shure,不管Haskell是否已经解析了其中的所有数据。

其他回答

为什么c#的List<T>.AddRange()不让我添加T的子类型的元素?阀门列表< T > () ! 微软只需要多写一行代码:

public void AddRange<S>(
    IEnumerable<S> collection
) where S : T

Scheme中没有保留标识符。因此,下面的表达式的值为1:

((lambda (lambda) lambda) (let ((let 1)) let))

注意,给定作用域内的定义是有限制的:任何定义都不能重新定义用于在该作用域内定义标识符的标识符,因此下面是一个语法错误:

(begin (define define 1) define)

在PHP中,字符串字母不能像在C中那样使用,你需要使用ord()和chr()来将数字转换为字符,反之亦然:"a" != 97,但ord("a") == 97。

不过,有一个例外:

for ($i = 'a'; $i < 'z'; $i++) {
    print "$i ";
}

将打印字母a到y,就像你所期望的,就像它是C风格的数据类型一样。

但是,如果将测试条件更改为<=,它将不会像您想象的那样输出a到z,而是输出a到yz!(共打印676项)

同样,如果您将676项列表中“z”后面的“z”更改为“aa”,并再次将测试条件更改为<,您将只看到“a”被打印出来!不是像你想的那样从a到z。

如果你将增量变量改为$i+=2,它将再次只打印“a”!唯一的方法是按顺序使用$i++, $i++,现在它像预期的那样工作。

尽管如此,这是PHP中输出字母a-z组合的好方法,尽管实际使用起来非常困难。

A very tiny thing that annoyed me in COBOL was that there was no dedicated modulo operation. Instead you could do a division specifying that you only wanted whole number results and store the rest in a different variable. Since COBOL is very sensitive when it comes to variables that means that you ended up with a variable you didn't really need, i.e. the actual result of the division. This is the story of how I once named a variable "USELESS" - that was the most appropriate name I could think of.

在C中,a[b][C]与C [b[a]]完全相同。