public static Goal Recurse(Func <Kanren, Goal> body, Kanren x) { return(state => new[] { new State { substitutions = state.substitutions, next = state.next, immature = body(x) } }); }
static Goal Fives(Kanren x) { return x == 5 | Kanren.Recurse(Fives, x); }
static Goal OneAndNine(Kanren x) { return x == 1 & x == 9; }
static Goal DoublyNestedArray() { return(Kanren.Exists((x, z) => z == new object[] { x, 2, 9 }& x == new[] { 3, 99 })); }
static Goal ArrayDisequality() { return(Kanren.Exists(x => x == new[] { 1, 2, 3 }& Kanren.Exists(z => z == x & z == new[] { 1, 2 }))); }
static Goal NestedArray() { return(Kanren.Exists(x => x == 99 & Kanren.Exists(z => z == new object[] { x, 2, 9 }))); }
static Goal Array() { return(Kanren.Exists(z => z == new[] { 1, 2, 9 })); }
static void Main(string[] args) { var x = Simple().Search(Kanren.EmptyState); Console.WriteLine("\r\nSimple:"); Print(x); var s = Simple2().Search(Kanren.EmptyState); Console.WriteLine("\r\nSimple2:"); Print(s); var y = SimpleConj().Search(Kanren.EmptyState); Console.WriteLine("\r\nSimpleConj:"); Print(y); var fv = Kanren.Exists(Fives); Console.WriteLine("\r\nFives:"); Print(fv.Search(Kanren.EmptyState)); var oan = Kanren.Exists(OneAndNine); Console.WriteLine("\r\nOne and Nine:"); Print(oan.Search(Kanren.EmptyState)); var fs = FivesAndSixes(); Console.WriteLine("\r\nFives and Sixes:"); Print(fs.Search(Kanren.EmptyState)); var a = Array(); Console.WriteLine("\r\nArray:"); Print(a.Search(Kanren.EmptyState)); var n = NestedArray(); Console.WriteLine("\r\nNestedArray:"); Print(n.Search(Kanren.EmptyState)); var ae = ArrayEquality(); Console.WriteLine("\r\nArrayEquality:"); Print(ae.Search(Kanren.EmptyState)); var ad = ArrayDisequality(); Console.WriteLine("\r\nArrayDisequality:"); Print(ad.Search(Kanren.EmptyState)); var dn = DoublyNestedArray(); Console.WriteLine("\r\nDoubleNestedArray:"); Print(dn.Search(Kanren.EmptyState)); // loops forever: //var fx = FivesXorSixes(); //Console.WriteLine("\r\nFives xor Sixes:"); //Print(fx.Search(Kanren.EmptyState)); Console.WriteLine("Please press enter..."); Console.ReadLine(); }
static Goal FivesAndSixes() { return(Kanren.Exists(x => Fives(x) | Sixes(x))); }
static Goal Sixes(Kanren x) { return(6 == x | Kanren.Recurse(Sixes, x)); }
static Goal Fives(Kanren x) { return(x == 5 | Kanren.Recurse(Fives, x)); }
static Goal OneAndNine(Kanren x) { return(x == 1 & x == 9); }
public static Goal SimpleConj() { return(Kanren.Exists(x => x == 5) & Kanren.Exists(y => y == 5 | y == 6)); }
public static Goal Simple2() { return(Kanren.Exists(x => x == 5 & Kanren.Exists(y => x == y))); }
static Goal Sixes(Kanren x) { return 6 == x | Kanren.Recurse(Sixes, x); }
static Goal FivesXorSixes() { return(Kanren.Exists(z => Fives(z) & Sixes(z))); }
public static Goal Simple() { return(Kanren.Exists(x => x == 5 | x == 6)); }