在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Common Lisp中,零维数组是很奇怪的,而且很自然地,它们具有读取语法。
? (aref #0A5)
5
其他回答
我几年前使用的一个Fortran编译器有一个有趣的特性:(A)数字先存储在高字节;(b)数字按地址传递给子程序;(c)没有在编译时检查长度。
所以你可以写一个这样的程序:(如果我把语法弄乱了,请原谅。我已经很久没有写Fortran了。)
INTEGER*2 FUNCTION TIMESTWO (INTEGER*2 N)
RETURN N*2
... THEN CALL THIS SOMEWHERE WITH A LONG INTEGER ...
INTEGER*4 I, J
I=42
J=TIMESTWO(I)
J的最终值是…零!
为什么?因为传入的值是4个字节,但被调用的函数只查看前两个字节。由于前两个是0,它将0乘以2并返回它。然后将此返回值转换回四个字节。
当我第一次遇到它时,它非常神秘。几乎我传递给某些函数的每个数字都被解释为零!
Haskell's use of Maybe and Just. Maybe a is a type constructor that returns a type of Just a, but Maybe Int won't accept just an Int, it requires it to be a Just Int or Nothing. So in essence in haskell parlance Just Int is about as much of an Int as an apple is an orange. The only connection is that Just 5 returns a type of Maybe Interger, which can be constructed with the function Just and an Integer argument. This makes sense but is about as hard to explain as it can theoretically be, which is the purpose of haskell right? So is Just really JustKindaLikeButNotAtAll yea sorta, and is Maybe really a KindaLooksLikeOrIsNothing, yea sorta again.
-- Create a function that returns a Maybe Int, and return a 5, which know is definitly Int'able
> let x :: Maybe Int; x = 5;
<interactive>:1:24:
No instance for (Num (Maybe Int))
arising from the literal `5' at <interactive>:1:24
Possible fix: add an instance declaration for (Num (Maybe Int))
In the expression: 5
In the definition of `x': x = 5
> Just 5
Just 5
it :: Maybe Integer
-- Create a function x which takes an Int
> let x :: Int -> Int; x _ = 0;
x :: Int -> Int
-- Try to give it a Just Int
> x $ Just 5
<interactive>:1:4:
Couldn't match expected type `Int' against inferred type `Maybe t'
In the second argument of `($)', namely `Just 5'
In the expression: x $ Just 5
In the definition of `it': it = x $ Just 5
祝你好运读到这篇文章,我希望它是正确的。
这是我的两分钱。在c++中:
int* t = new int(15);
delete t;
c#中的“动态”。
因为智能感知、类型安全和决定论会随着“动态”关键字的第一次使用而立即消失,因此所有必须与RAD或python受害者一起工作的人的日子都被毁了。
X = X + 1
当我还是初学者的时候,这很难消化,而现在函数式语言不使用它了,这就更难了!
如果你不明白这有多奇怪:把等号看作断言语句,而不是赋值操作,就像你在基础代数中经常做的那样,那么这相当于说“0 = 1”。