Example #1
0
 public static Goal Recurse(Func <Kanren, Goal> body, Kanren x)
 {
     return(state => new[]
     {
         new State {
             substitutions = state.substitutions, next = state.next, immature = body(x)
         }
     });
 }
Example #2
0
 static Goal Fives(Kanren x)
 {
     return x == 5 | Kanren.Recurse(Fives, x);
 }
Example #3
0
 static Goal OneAndNine(Kanren x)
 {
     return x == 1 & x == 9;
 }
Example #4
0
 static Goal DoublyNestedArray()
 {
     return(Kanren.Exists((x, z) => z == new object[] { x, 2, 9 }& x == new[] { 3, 99 }));
 }
Example #5
0
 static Goal ArrayDisequality()
 {
     return(Kanren.Exists(x => x == new[] { 1, 2, 3 }& Kanren.Exists(z => z == x & z == new[] { 1, 2 })));
 }
Example #6
0
 static Goal NestedArray()
 {
     return(Kanren.Exists(x => x == 99 & Kanren.Exists(z => z == new object[] { x, 2, 9 })));
 }
Example #7
0
 static Goal Array()
 {
     return(Kanren.Exists(z => z == new[] { 1, 2, 9 }));
 }
Example #8
0
        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();
        }
Example #9
0
 static Goal FivesAndSixes()
 {
     return(Kanren.Exists(x => Fives(x) | Sixes(x)));
 }
Example #10
0
 static Goal Sixes(Kanren x)
 {
     return(6 == x | Kanren.Recurse(Sixes, x));
 }
Example #11
0
 static Goal Fives(Kanren x)
 {
     return(x == 5 | Kanren.Recurse(Fives, x));
 }
Example #12
0
 static Goal OneAndNine(Kanren x)
 {
     return(x == 1 & x == 9);
 }
Example #13
0
 public static Goal SimpleConj()
 {
     return(Kanren.Exists(x => x == 5)
            & Kanren.Exists(y => y == 5 | y == 6));
 }
Example #14
0
 public static Goal Simple2()
 {
     return(Kanren.Exists(x => x == 5 & Kanren.Exists(y => x == y)));
 }
Example #15
0
 static Goal Sixes(Kanren x)
 {
     return 6 == x | Kanren.Recurse(Sixes, x);
 }
Example #16
0
 static Goal FivesXorSixes()
 {
     return(Kanren.Exists(z => Fives(z) & Sixes(z)));
 }
Example #17
0
 public static Goal Simple()
 {
     return(Kanren.Exists(x => x == 5 | x == 6));
 }