在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在J中,大多数原语(也就是函数)是一元的(一个参数)或二元的(两个参数,一个在左边,一个在右边)。但是修正原语需要3个(我认为这是唯一一个,除了foreign)。这是可以理解的,它需要3个,但它只是看起来…一开始是错的。
vector =: i. 10 NB. Vector will be 0 1 2 3 4 5 6 7 8 9
(10) (0) } vector NB. Will yield 10 1 2 3 4 5 6 7 8 9
其他回答
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.
这并不是说它被大量使用,而是c++的“返回对静态大小数组的引用”的语法很奇怪:
struct SuperFoo {
int (&getFoo() const)[10] {
static int foo[10];
return foo;
}
}
在上述情况下,Ofc方法可以声明为静态const
在x++ (Microsoft Dynamics AX):
1)需要在单独的行上使用分号(;)将变量声明与语句分开(至少在4.0版本之前)
int i;
int myArray[5];
;
i = 1;
2)数组索引是基于1的,所以你不允许像in那样使用索引0(零)从数组中读取
int myArray[5];
;
print myArray[0]; // runtime error
这并不奇怪,但是你可以在赋值的左边使用0索引,比如in
int myArray[5];
;
myArray[2] = 102;
myArray[0] = 100; // this is strange
print myArray[2]; // expcting 102?
会发生什么呢?数组被初始化为它的默认值,无论赋值中使用了什么值。上面的代码输出0(零)!
其余的这些都没有令人震惊的Ruby触发器操作符:
p = proc {|a,b| a..b ? "yes" : "no" }
p[false,false] => "no"
p[true,false] => "yes"
p[false,false] => "yes" # ???
p[false,true] => "yes"
p[false,false] => "no"
是的,程序状态存储在解释器的解析树中。这就是为什么开发一个兼容的Ruby实现要花很长时间的原因。但是我原谅你,Ruby
可能已经说过了(也许这对一些人来说并不奇怪),但我认为这很酷:
在Javascript中,声明函数接受的参数只是为了方便程序员。通过函数调用传递的所有变量都可以通过关键字“arguments”访问。所以下面会提醒“world”:
<script type="text/javascript">
function blah(){
alert(arguments[1]);
}
blah("hello", "world");
</script>
注意,虽然这些参数看起来像是存储在数组中(因为您可以以与数组元素相同的方式访问对象属性),但事实并非如此。arguments是一个对象,而不是数组(因此,它们是存储在数值索引下的对象属性),如下例所示(typeOf函数来自Crockford的JavaScript补救页面):
argumentsExample = function(){
console.log(typeOf(arguments));
anArray = [];
console.log(typeOf(anArray));
anObject = {};
console.log(typeOf(anObject));
}
function typeOf(value) {
var s = typeof value;
if (s === 'object') {
if (value) {
if (typeof value.length === 'number' &&
!(value.propertyIsEnumerable('length')) &&
typeof value.splice === 'function') {
s = 'array';
}
} else {
s = 'null';
}
}
return s;
}
argumentsExample("a", "b");