我似乎无法弄清楚如何将'when'关键字添加到应该表现为'if'的BOO 。我想我可以制定一个方法,但是我不能像使用 if 那样移动 when 。任何指针将不胜感激。
-标记
这会做你想要的:
import Boo.Lang.Compiler.Ast
import Boo.Lang.Compiler.MetaProgramming
macro when:
return [|
if $(when.Arguments[0]):
$(when.Block)
|]
x = 1
when x == 1:
print "x equals one"
when x == 2:
print "x equals two"
顺便说一句,请随时(也)在 Boo 邮件列表上询问以更快地获得(更多)答案;)
This would be a job for a macro. From the page you linked to, it seems that Boo has syntactic macros.
As an aside note, why do you need an exact duplicate of an existing functionality?