在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Perl中,你可以做到:
my $test = "Hello World";
substr($test, 0, 5) = "Goodbye";
print $test;
这在其他语言中可行吗?
其他回答
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.
PHP
来自在线文档: string implode (string $glue, array $pieces) -用字符串连接数组元素 注意:由于历史原因,implode()可以以任意一种顺序接受其形参。
这是可行的:implode($someArray, $glue)
希望他们能在PHP 6中消除这些历史怪癖。
大约20年前,我用一个编译器为一种叫做Coral的语言工作,它允许我声明只写变量!
不过,这是有道理的,因为它们是全球性的,被用作一种信号机制。一个进程写入值,另一个进程读取值。
Processing (processing.org)是一种基于Java的语言。简单来说,处理编译器是将特定于处理的语法转换为Java的Java预处理器。
由于语言的设计,它有一些惊喜:
Processing的类被编译成Java内部类,这会引起一些麻烦,比如私有变量并不是真正私有的
class Foo {
private int var = 0; // compiles fine
}
void setup() {
Foo f = new Foo();
print(f.var); // but does not causes compile error
}
同样缺少draw()函数会导致事件处理程序不被调用:
// void draw() {} // if you forgot to include this
void mousePressed() {
print("this is never called");
}
在PowerShell中,你可以重命名变量:
> $a = "some value"
> $b = "a"
> $c = "d"
> Rename-Item variable:$b $c
> $d
some value
间接间接!PHP!
字面也有用:
> Rename-Item variable:d e
> $e
some value