简体   繁体   English

在Boo中定义运算符

[英]Defining operators in Boo

I'm looking to move some of my lighter weight metaprogramming from Nemerle to Boo and I'm trying to figure out how to define custom operators. 我希望将一些较轻量级的元编程从Nemerle移到Boo,并且试图弄清楚如何定义自定义运算符。 For example, I can do the following in Nemerle: 例如,我可以在Nemerle中执行以下操作:

macro @<-(func, v) {
    <[ $func($v) ]>
}

Then these two are equivalent: 那么这两个是等效的:

foo <- 5;
foo(5);

I can't find a way of doing this in Boo -- any ideas? 我在Boo中找不到做到这一点的方法-有什么想法吗?

虽然Boo通过定义适当的静态运算符功能( op_addition )支持运算符重载,并且还支持语法宏,但目前不支持创建自定义运算符。

I'm not sure if this is exactly what you need but you can create syntactic macros in Boo. 我不确定这是否正是您所需要的,但是您可以在Boo中创建语法宏。 There's some information on the CodeHaus site, http://boo.codehaus.org/Syntactic+Macros , but the syntax has changed in one of the recent releases. 在CodeHaus站点上有一些信息, http: //boo.codehaus.org/Syntactic+Macros,但是语法在最近发行的版本之一中已更改。 I don't know of any tutorials on the new syntax but the source release for Boo 0.8.2 has some examples (some of the language structures are implemented as macros). 我不知道有关新语法的任何教程,但是Boo 0.8.2的源发行版提供了一些示例(某些语言结构实现为宏)。 If you don't want to download the full source a view of the SVN repository is available, https://svn.codehaus.org/boo/boo/trunk/src/Boo.Lang.Extensions/Macros/ . 如果您不想下载完整的源代码,则可以查看SVN信息库的视图, 网址为https://svn.codehaus.org/boo/boo/trunk/src/Boo.Lang.Extensions/Macros/ The assert macro would be a good place to start. 断言宏将是一个很好的起点。

HTH 高温超导

Stoo 斯托

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM