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

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


当前回答

Haskell又说:

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

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

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

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

其他回答

在Common Lisp中,零维数组是很奇怪的,而且很自然地,它们具有读取语法。

? (aref #0A5)
5

在PHP中,你可以这样做:

System.out.print("hello");

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.

这不是一个奇怪的功能,事实上,如果你仔细想想,它是完全有意义的,但还是给了我一个WTF时刻。

在c++(和c#)中,基类的子类不能访问基实例上的私有和受保护成员。

class Base {
protected:
 m_fooBar;
};

class Derived: public Base {
public:
 void Test(Base& baseInstance) {
  m_fooBar=1; //OK
  baseInstance.m_fooBar = 1; //Badness
  //This, however is OK:
  ((Derived&)baseInstance).m_fooBar = 1; //OK
 }
};

这是我最喜欢的一个,你可以在Java中不使用main()来执行println。

这将编译和运行,给出println,但也有一个异常(java.lang。NoSuchMethodError:主要)

class Test {
    static {
        System.out.println("I'm printing in Java without main()");
    }
}