Linqdigestion
Today I've downloaded the May CTP of Linq . I was expecting something more new but... Anyway, there is a lot of cool examples on it. One of them, LogicProgramming, builds a small Logic Programming lenguage inside C#!!!. You can do something like:
Rules rules = new Rules();
Func1 isToy = Func.Arity1("isToy");
Func2 playsWith = Func.Arity2("playsWith");
Func2 likes = Func.Arity2("likes");
// A doll is a toy.
rules += isToy("doll");
// A train is a toy.
rules += isToy("train");
// Ann plays with a train.
rules += playsWith("ann","train");
// John likes a toy if Ann likes that toy.
rules += Y => likes("john",Y)==likes("ann",Y);
// Ann likes toys that she plays with.
rules += X => likes("ann",X)==(isToy(X) & playsWith("ann",X));
// Ask a question: What does John like?
foreach(string s in rules.Solve
Console.WriteLine(s);
}
Cool right? The code is full of lambda expressions, extensional methods... swahili.
No comments:
Post a Comment