-
Notifications
You must be signed in to change notification settings - Fork 89
Define operator inline function
NN--- edited this page Apr 11, 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 num = 9;
def res = num %++ 4;
def res = res &++ 3;
WriteLine(res);
- Execution Result:
21
both elements are equal
[Copyright ©](Terms of use, legal notice)