- From: <jos.deroo@agfa.com>
- Date: Thu, 29 Mar 2007 01:50:59 +0200
- To: www-archive@w3.org
- Message-ID: <OF4F36BC76.73A5A73E-ONC12572AC.00830275-C12572AC.008302E7@agfa.com>
mono Graph.exe where Graph.cs is using System; using System.Collections.Generic; using YieldProlog; namespace eg { //@prefix eg: <http://eulersharp.sf.net/graph#>. class Graph { static void Main(string[] args) { YP.assertFact("eg:twoway", new object[] { "eg:paris", "eg:orleans" }); YP.assertFact("eg:twoway", new object[] { "eg:paris", "eg:chartres" }); YP.assertFact("eg:twoway", new object[] { "eg:paris", "eg:amiens" }); YP.assertFact("eg:twoway", new object[] { "eg:orleans", "eg:blois" }); YP.assertFact("eg:twoway", new object[] { "eg:orleans", "eg:bourges" }); YP.assertFact("eg:twoway", new object[] { "eg:blois", "eg:tours" }); YP.assertFact("eg:twoway", new object[] { "eg:chartres", "eg:lemans" }); YP.assertFact("eg:twoway", new object[] { "eg:lemans", "eg:angers" }); YP.assertFact("eg:twoway", new object[] { "eg:lemans", "eg:tours" }); YP.assertFact("eg:twoway", new object[] { "eg:angers", "eg:nantes" }); foreach (bool l in go()); } public static IEnumerable<bool> go() { Variable A = new Variable(); Variable B = new Variable(); foreach (bool l2 in path(A, B)) { YP.write(new Functor2("eg:path", A, B) + "."); YP.nl(); } yield return false; } static IEnumerable<bool> twoway(object X, object Y) { return YP.matchFact("eg:twoway", new object[] { X, Y }); } public static IEnumerable<bool> path(object X, object Y) { //System.Diagnostics.StackTrace st = new System.Diagnostics.StackTrace(1); foreach (bool l2 in twoway(X, Y)) { yield return false; } foreach (bool l2 in twoway(Y, X)) { yield return false; } Variable Z = new Variable(); foreach (bool l2 in twoway(X, Z)) { foreach (bool l3 in path(Z, Y)) { yield return false; } } } } } gives eg:path(eg:paris, eg:orleans). eg:path(eg:paris, eg:chartres). eg:path(eg:paris, eg:amiens). eg:path(eg:orleans, eg:blois). eg:path(eg:orleans, eg:bourges). eg:path(eg:blois, eg:tours). eg:path(eg:chartres, eg:lemans). eg:path(eg:lemans, eg:angers). eg:path(eg:lemans, eg:tours). eg:path(eg:angers, eg:nantes). eg:path(eg:orleans, eg:paris). eg:path(eg:chartres, eg:paris). eg:path(eg:amiens, eg:paris). eg:path(eg:blois, eg:orleans). eg:path(eg:bourges, eg:orleans). eg:path(eg:tours, eg:blois). eg:path(eg:lemans, eg:chartres). eg:path(eg:angers, eg:lemans). eg:path(eg:tours, eg:lemans). eg:path(eg:nantes, eg:angers). eg:path(eg:paris, eg:blois). eg:path(eg:paris, eg:bourges). eg:path(eg:paris, eg:paris). eg:path(eg:paris, eg:tours). eg:path(eg:paris, eg:orleans). eg:path(eg:paris, eg:blois). eg:path(eg:paris, eg:lemans). eg:path(eg:paris, eg:orleans). eg:path(eg:paris, eg:lemans). eg:path(eg:paris, eg:paris). eg:path(eg:paris, eg:angers). eg:path(eg:paris, eg:tours). eg:path(eg:paris, eg:chartres). eg:path(eg:paris, eg:nantes). eg:path(eg:paris, eg:lemans). eg:path(eg:paris, eg:angers). eg:path(eg:paris, eg:blois). eg:path(eg:paris, eg:lemans). eg:path(eg:paris, eg:paris). eg:path(eg:orleans, eg:tours). eg:path(eg:orleans, eg:orleans). eg:path(eg:orleans, eg:blois). eg:path(eg:orleans, eg:lemans). eg:path(eg:orleans, eg:orleans). eg:path(eg:blois, eg:blois). eg:path(eg:blois, eg:lemans). eg:path(eg:chartres, eg:angers). eg:path(eg:chartres, eg:tours). eg:path(eg:chartres, eg:chartres). eg:path(eg:chartres, eg:nantes). eg:path(eg:chartres, eg:lemans). eg:path(eg:chartres, eg:angers). eg:path(eg:chartres, eg:blois). eg:path(eg:chartres, eg:lemans). eg:path(eg:lemans, eg:nantes). eg:path(eg:lemans, eg:lemans). eg:path(eg:lemans, eg:angers). eg:path(eg:lemans, eg:blois). eg:path(eg:lemans, eg:lemans). eg:path(eg:angers, eg:angers). which concurs with Yap Prolog result and speed is similar; waw! and is similar result for js and python code
Received on Wednesday, 28 March 2007 23:51:12 UTC