Exemplo n.º 1
0
 private static Stream MakeStream(Substitution curr, DelayedStream getRest)
 {
     return(new Stream()
     {
         Curr = curr,
         GetRest = getRest
     });
 }
Exemplo n.º 2
0
        public static IList <object> Run(int?n, Func <KRunner, FreshVariable, Goal> body)
        {
            var k = new KRunner();
            // 定义待求解的未知量q
            var q = k.Fresh();
            // 执行body,得到最终目标g
            var g = body(k, q);
            // 初始上下文是一个空替换,应用到g,得到包含可行替换的Stream s
            var s = g(Substitution.Empty());

            // 从s中取出前n个(n==null则取所有)替换,查找各个替换下q的解,并给自由变量换个好看的符号。
            return(s.MapAndTake(n, sub => Renumber(sub.Walk(q))));
        }
Exemplo n.º 3
0
 public static Stream Unit(Substitution sub)
 {
     return(MakeStream(sub, () => Empty()));
 }
Exemplo n.º 4
0
 private Substitution(Substitution p, FreshVariable var, object val)
 {
     parent = p;
     Var    = var;
     Val    = val;
 }