似非Restriction Operators
・The LINQ Project
C#3.0とLINQが発表され、各地で盛り上がっているよーですが、仕事で嵌っていて全く情報が集められてません。
悔しいのでNemerleで対抗です。よーわからないけど見様見真似。(^^;
using Nemerle.Utility; [Record] class Person { [Accessor] mutable name : string = ""; [Accessor] mutable age : int = 0; [Accessor] mutable addr : string = ""; } def l1 = [1, 2, 3, 4, 5]; def l2 = from n in l1 where_ n % 2 == 0 select n; l2.Iter (fun (x) { Nemerle.IO.printf("%d\n", x)}); def a1 = array (3) : array [Person]; a1 [0] = Person ("foo", 19, "Sapporo"); a1 [1] = Person ("bar", 20, "Yokohama"); a1 [2] = Person ("baz", 21, "Tokyo"); def l3 = from p in a1 where_ p.Age >= 20 select (p.Addr, p.Age, p.Name); l3.Iter (fun (x) { Nemerle.IO.printf("%s\n", x.ToString ())}); /* 結果 2 4 (Yokohama, 20, bar) (Tokyo, 21, baz) */
おお!、すげーぜ、Nemerle!!
・・・嘘です、見た目だけです。その正体は、
using Nemerle.Compiler; using Nemerle.Compiler.Parsetree; macro from (element, collection, condition, items) syntax ("from", element, "in", collection, "where_", condition, "select", items) { def x = Macros.NewSymbol (); <[ mutable $(x : name) = []; foreach ($element in $collection) { when ($condition) $(x : name) ::= $items; } $(x : name).Reverse(); ]> }
ただのマクロでした。(^^;
そろそろ仕事に戻らないと。遊びたいよぉ・・・