Anonymous - 2010-06-24

Hi,
I used YP Compiler to convert append in prolog to append in C#, just to get a feel for YP.

prologCode =
            "append(List,,List). \n" +
            "append(,,List2) :- \n" +
            "append(Result,List1,List2). \n";

public static IEnumerable<bool> append(object arg1, object arg2, object arg3)
    {
        {
            Variable List = new Variable();
            foreach (bool l2 in YP.unify(arg1, List))
            {
                foreach (bool l3 in YP.unify(arg2, Atom.NIL))
                {
                    foreach (bool l4 in YP.unify(arg3, List))
                    {
                        yield return false;
                    }
                }
            }
        }
        {
            object List2 = arg3;
            Variable Item = new Variable();
            Variable Result = new Variable();
            Variable List1 = new Variable();
            foreach (bool l2 in YP.unify(arg1, new ListPair(Item, Result)))
            {
                foreach (bool l3 in YP.unify(arg2, new ListPair(Item, List1)))
                {
                    foreach (bool l4 in append(Result, List1, List2))
                    {
                        yield return false;
                    }
                }
            }
        }
    }

The append in C# copies all the variables before using them? Is this necessary? In other words is there a more elegant implementation for append using YP directly?

btw great library.