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

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


当前回答

Tcl中的连接是将两个字符串添加为一个字符串:

set s1 "prime"
set s2 "number"
set s3 $s1$s2
puts s3

输出为

primenumber

其他回答

在JavaScript中,方法的结果取决于所放置的样式花括号。这是K&R风格,其中括号放在方法签名之后和return语句之后:

var foo = function() {
  return {
    key: 'value'
  };
}

foo() // returns an object here

现在,如果我将这段代码格式化为Allman风格,其中括号总是放在新行上,结果是不同的:

var foo = function()
{
  return
  {
    key: 'value'
  };
}

foo() // returns undefined here

如何来吗?在JavaScript中,如果您不自己做,语言会自动在每行末尾放置分号。所以在最后一个代码片段中真正发生的是这样的:

var foo = function()
{
  return; // here's actually a semicolon, automatically set by JavaScript!
  {
    key: 'value'
  };
}

因此,如果调用foo(),方法中的第一个语句将是一个返回语句,该语句将返回undefined,并且不会执行后面的其他语句。

在fortran中(当然是77,可能在95中也是如此),未声明的变量和以I到N开头的参数(“In”组)将是INTEGER,所有其他未声明的变量和参数将是REAL(源)。这与“在某些情况下可选的空白”相结合,导致了最著名的错误之一。

正如弗雷德·韦伯在1990年的《另类民间传说:计算机》一书中所说:

I worked at Nasa during the summer of 1963. The group I was working in was doing preliminary work on the Mission Control Center computer systems and programs. My office mate had the job of testing out an orbit computation program which had been used during the Mercury flights. Running some test data with known answers through it, he was getting answers that were close, but not accurate enough. So, he started looking for numerical problems in the algorithm, checking to make sure his tests data was really correct, etc. After a couple of weeks with no results, he came across a DO statement, in the form: DO 10 I=1.10 This statement was interpreted by the compiler (correctly) as: DO10I = 1.10 The programmer had clearly intended: DO 10 I = 1, 10 After changing the . to a , the program results were correct to the desired accuracy. Apparently, the program's answers had been "good enough" for the sub-orbital Mercury flights, so no one suspected a bug until they tried to get greater accuracy, in anticipation of later orbital and moon flights. As far as I know, this particular bug was never blamed for any actual failure of a space flight, but the other details here seem close enough that I'm sure this incident is the source of the DO story.

我认为这是一个很大的WTF,如果DO10I被作为DO10I,并且反过来,因为隐式声明被认为是类型REAL。这是个很棒的故事。

Algol通过名称传递(使用C语法说明):

int a[3] = { 1, 2, 3 };
int i = 1;

void f(int j)
{
    int k;
    k = j;  // k = 2
    i = 0;
    k = j;  // k = 1 (!?!)    
}

int main()
{
    f(a[i]);
}

从技术上讲,WTF不是一种语言,而是一种架构。

http://www.6502.org/tutorials/6502opcodes.html#JMP

6502总成,间接JMP:

注意,间接跳转没有进位,因此: 间接跳转绝对不能使用 从最后一个字节开始的向量 一页的 例如,如果地址$3000包含$40,$30FF包含$80,$3100包含$50,JMP ($30FF)的结果将是控制权转移到$4080,而不是你想要的$5080,即6502从$30FF获取地址的低字节,从$3000获取高字节。

因此,在代码中添加一个字节可能会使间接跳转偏离目标。

叫/ cc。Call/cc将一个表示程序其余部分的函数传递给程序体。