铁锈的特征系统是图灵完整的。该箱采用特征求值的原则来实现四次评价的必备特征,并提供了四次评价的原则!将语法转换为特征表达式的宏。
这里是一个简单的阶乘实现,这里唯一的非标准单词是pred,它是一个减运算符,相当于1-:
Fourth!(:阶乘(n--n)1交换fact0;:fact0(n n--n)dup 1=if drop Else DUP ROT*SWAP Pred fact0 Then;5阶乘。);
这个可以打印120。正如您所看到的,您不仅可以轻松地定义函数,甚至还可以进行条件递归!现在看看编译成特征表达式后的样子(由Cargo Expand提供):
发布特征阶乘{type Result;}为节点实施<;V,N&>;阶乘,其中Self:One,<;Self As One>;::Result:SWAP,<;<;Self As>;::Result AS SWAP>;::Result:Fact0,{type Result=<;<;::Result As One>;::Result As}酒吧特性事实0{类型结果;}为节点<;V,N&>;实施<;V,N&>;fact0,其中SELF:DUP,<;SELF AS DUP&>;::RESULT:ONE,<;<;SELF AS DUP&>;::RESULT AS ONE;::RESULT:EQ,<;<;::RESULT AS ONE&gT;Self As DUP&>;::Result As EQ&>;:Result As iff&>;::Result:Drop,<;<;Self As DUP&>;:Result As EQ&>;::Result As Drop&>;::Result AS DUP&>;::Result AS DUP&>;<;<;Self as DUP>;::Result As Drop&>;::Result As DUP&>;::Result As DUP&>;::Result AS DUP&>;<;<;::Result as Else&>;:Result as Else As DUP&>;::Result as Else As DUP&>;:Result As EQ&>;:Result As Iq&>;:Result As Drop&>;:Result As Else As DUP&>;::Result As DUP&>;::Result As Else&>;:Result As Else&>;:Result As DUP&>;::Result As Else&>;:Result As DUP&>;::Result As DUP&>。<;<;SELF AS DUP&>;:RESULT AS EQ&>;:RESULT AS EQ&>;::RESULT AS DUP&>;::RESULT AS ELELF&>;:RESULT AS ROT&>;::RESULT:MULT,<;<;SELF AS DUP&>;::RESULT AS ONE>;::Result as DUP&>;::Result as One>;::Result as Elf&>;:Result as DUP&>;:Result as DUP&>;:Result as Rot&>;:Result as MULT&>;::Result:SWAP,<;<;<;Self AS DUP&>;:Result As One>;:Result AS EQ&>;:Result As If>;:Result As If>;:Result As Iq>;:Result as Elf>;:Result as Iq>;:Result as Iq>;::::结果为多个交换&>;::结果为多个交换&>;::结果为多个交换&>;::结果为多个交换&>;::结果为自身为重复&>;::结果为一个:结果为等式;::结果为删除&>;::结果为删除&>;::结果为丢弃(&>t;::结果为删除>;::结果为删除>;::结果为删除>;::结果为删除;::Result as pred&>;::Result as pred&>;:Result as<;<;&>;:Result As One&>;:Result As Eq&>;:Result As Iq&>;:Result As Drop&>;::Result As Pred&>;::Result as Else&>;::Result as Pred&>;::Result as Fact0&>;::Result:Then{TYPE RESULT=<;<;SELF AS DUP&>;::RESULT AS OUT&>;::RESULT AS EQ&>;:RESULT AS EQ&>;::RESULT AS DUP&>;:Result AS DUP&>;:Result AS ROT&>;:Result AS MULT&>;::Result AS SWAP&>;::Result AS Pred>;::Result AS Fact0>;::Result AS Then>;::Result as DUP&>;}println!(";{}&34;,<;<。::result::eval());
正如您在上面看到的,实际上支持相当多的内容。特征评估中的每个操作都会重新导出到堆栈上(除非以不同方式完成),并且提供了一汽额外的堆栈操作。有关详细信息,请参阅文档。