简体   繁体   中英

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. For example, I can do the following in 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通过定义适当的静态运算符功能( op_addition )支持运算符重载,并且还支持语法宏,但目前不支持创建自定义运算符。

I'm not sure if this is exactly what you need but you can create syntactic macros in 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. 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). 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/ . The assert macro would be a good place to start.

HTH

Stoo

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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