[svn] r6219: nemerle/trunk: macros/operators.n
ncc/testsuite/positive/basic-macros.n
nazgul
svnadmin at nemerle.org
Wed May 3 20:03:01 CEST 2006
Log:
Add macro implementing C# 3.0 lambda expressions
Author: nazgul
Date: Wed May 3 20:02:42 2006
New Revision: 6219
Modified:
nemerle/trunk/macros/operators.n
nemerle/trunk/ncc/testsuite/positive/basic-macros.n
Modified: nemerle/trunk/macros/operators.n
==============================================================================
--- nemerle/trunk/macros/operators.n (original)
+++ nemerle/trunk/macros/operators.n Wed May 3 20:02:42 2006
@@ -184,4 +184,22 @@
def (cached, safe) = Operators.cache_assign_expr (e1);
<[ $cached; $safe = $e2 :: $safe ]>
}
+
+ macro @=> (parms, body) {
+ def convert_to_parm (x) {
+ | <[ $(nm : name) ]> => <[ parameter: $(nm : name) ]>
+ | <[ $(nm : name) : $ty ]> => <[ parameter: $(nm : name) : $ty ]>
+ | _ => Message.FatalError ($"unsupported syntax for parameter of 'parms => body' lambda expression: $x");
+ }
+
+ match (parms) {
+ | <[ (..$parms) ]> =>
+ def parms = parms.Map (convert_to_parm);
+ <[ fun (..$parms) { $body } ]>
+
+ | _ =>
+ def single = convert_to_parm (parms);
+ <[ fun (..$([single])) { $body } ]>
+ }
+ }
}
Modified: nemerle/trunk/ncc/testsuite/positive/basic-macros.n
==============================================================================
--- nemerle/trunk/ncc/testsuite/positive/basic-macros.n (original)
+++ nemerle/trunk/ncc/testsuite/positive/basic-macros.n Wed May 3 20:02:42 2006
@@ -303,6 +303,21 @@
foo ([1,2]);
}
+ TestCSharp3_0Lambda () : void {
+ printf ("----- Test C# 3.0's lambda expression syntax -----\n");
+ [1,2,4].Iter (x => System.Console.WriteLine (x));
+ def add = (x,y) => x + y;
+ System.Console.WriteLine (add (1,2));
+ def add = (x : string, y) => x + y;
+ System.Console.WriteLine (add ("1","2"));
+ def one = x : string => x.Substring (1);
+ System.Console.WriteLine (one ("aaa"));
+ def brace = x => { x + 1 };
+ System.Console.WriteLine (brace (1));
+ def one = (x : int) => x + 1;
+ System.Console.WriteLine (one(1));
+ }
+
Main () : void
{
@@ -314,6 +329,7 @@
TestForEach ();
TestRepeat ();
ClassForColors ().foo ();
+ TestCSharp3_0Lambda ();
}
}
@@ -393,5 +409,14 @@
aaaaa
----- Test colors and environments ------
bla 66 bla
+----- Test C# 3.0's lambda expression syntax -----
+1
+2
+4
+3
+12
+aa
+2
+2
END-OUTPUT
*/
More information about the svn
mailing list