-
Notifications
You must be signed in to change notification settings - Fork 89
Define operator inline function
CodingUnit edited this page Jan 13, 2012
·
6 revisions
- Category: Defining Operator
- Description: Define operator using inline function
- Code (in separate macro library):
namespace MacroLibrary2
{
macro @&++(e, e2)
{
<[ $e + $e2 + 1 ]>
}
}
- Code (you must include macro reference for first code):
using System;
using System.Console;
using Nemerle;
using MacroLibrary2;
// set operator priority and precedence
[assembly: Nemerle.Internal.OperatorAttribute ("", "%++", false, 240, 241)]
[assembly: Nemerle.Internal.OperatorAttribute ("MacroLibrary2", "&++", false, 283, 284)]
module Inline
{
public @%++(a : int, b : int) : int
{
a + b * 2
}
}
using Inline;
def a = 9;
def r = a %++ 4;
def r = r &++ 3;
WriteLine(r);
WriteLine(if (r == 21) "both elements are equal" else "elements not equal");
_ = ReadLine();```
- Execution Result:
21 both elements are equal
***
[Copyright ©](Terms of use, legal notice)