views:

303

answers:

2

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?

A: 

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

Stoo
+5  A: 

While Boo supports operator overloading by defining the appropriate static operator function (op_addition), and also supports syntactic macros, it does not support creating custom operators at this time.

Marcus Griep
Note however that "extensible syntax" (which is the only missing piece to allow this feature) is a Boo feature currently under development, so this should be available soon. I mean, eventually.
Avish