在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
在你看来,你遇到过的最令人惊讶、最怪异、最奇怪或最“WTF”的语言特性是什么?
请每个回答只回答一个特征。
当前回答
在Forth中,任何不包含空格的东西都可以是标识符(包含空格的东西需要做一些工作)。解析器首先检查事物是否定义了,在这种情况下,它被称为单词,如果没有,则检查它是否为数字。没有关键字。
无论如何,这意味着人们可以重新定义一个数字来表示其他东西:
: 0 1 ;
它创建了单词0,由1组成,不管它在执行时是什么。反过来,它会导致以下结果:
0 0 + .
2 Ok
另一方面,定义可以接管解析器本身——这是可以做到的 通过评论词。这意味着Forth程序实际上可以在中途变成一个完全不同语言的程序。事实上,这是Forth推荐的编程方式:首先你写你想要解决问题的语言,然后你解决问题。
其他回答
Java的Integer类的基转换静态方法。P似乎很少有语言内置了这个功能。
Perl的许多内置变量:
$# — not a comment! $0, $$, and $? — just like the shell variables by the same name $ˋ, $&, and $' — weird matching variables $" and $, — weird variables for list- and output-field-separators $! — like errno as a number but strerror(errno) as a string $_ — the stealth variable, always used and never seen $#_ — index number of the last subroutine argument... maybe @_ — the (non)names of the current function... maybe $@ — the last-raised exception %:: — the symbol table $:, $^, $~, $-, and $= — something to do with output formats $. and $% — input line number, output page number $/ and $\ — input and output record separators $| — output buffering controller $[ — change your array base from 0-based to 1-based to 42-based: WHEEE! $} — nothing at all, oddly enough! $<, $>, $(, $) — real and effective UIDs and GIDs @ISA — names of current package’s direct superclasses $^T — script start-up time in epoch seconds $^O — current operating system name $^V — what version of Perl this is
还有很多这样的东西。点击这里阅读完整列表。
VBScript的日期/时间文字(为什么这个仍然如此罕见?):
mydate = #1/2/2010 5:23 PM#
If mydate > #1/1/2010 17:00# Then ' ...
编辑:日期文字是相对的(那么它们在技术上是文字吗?):
mydate = #Jan 3# ' Jan 3 of the current year
VB。NET,因为它是编译的,所以不支持相对日期文字。只支持日期或时间字面量,但缺失的时间或日期被假定为零。
编辑[2]:当然,有一些奇怪的极端情况会出现相对日期……
mydate = #Feb 29# ' executed on 2010-01-05, yields 2/1/2029
这个古老的PHP宠儿本身并不完全是WTFish,但作用域解析错误是许多开发人员看到的事情之一,值得给一些WTF的爱:
$class = new StdClass();
$class::test();
PHP Parse error: syntax error, unexpected T_PAAMAYIM_NEKUDOTAYIM on line 3
一般来说,弱类型。
C:
printf("%c\n", 'a' + 3);
PHP:
echo 5 + "3";
还有太多其他语言。