Exemple #1
0
        //[MTAThread]
        public static void Main(string[] args0)
        {
            PingThreadFactories();
            bool demo = false;
            SetupProlog();

            if (demo)
            {
                DoQuery("asserta(fff(1))");
                DoQuery("asserta(fff(9))");
                DoQuery("nl");
                DoQuery("flush");

                PlAssert("father(martin, inka)");
                if (!PlCsDisabled)
                {
                    PlQuery.PlCall("assert(father(uwe, gloria))");
                    PlQuery.PlCall("assert(father(uwe, melanie))");
                    PlQuery.PlCall("assert(father(uwe, ayala))");
                    using (PlQuery q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)"))
                    {
                        foreach (PlTermV v in q.Solutions)
                            ConsoleTrace(ToCSString(v));

                        foreach (PlQueryVariables v in q.SolutionVariables)
                            ConsoleTrace(v["L"].ToString());


                        ConsoleTrace("all child's from uwe:");
                        q.Variables["P"].Unify("uwe");
                        foreach (PlQueryVariables v in q.SolutionVariables)
                            ConsoleTrace(v["C"].ToString());
                    }
                    //PlQuery.PlCall("ensure_loaded(library(thread_util))");
                    //Warning: [Thread 2] Thread running "thread_run_interactor" died on exception: thread_util:attach_console/0: Undefined procedure: thread_util:win_open_console/5
                    //PlQuery.PlCall("interactor");
                    //Delegate Foo0 = foo0;
                    RegisterPLCSForeigns();
                }

                PlAssert("tc2:-foo2(X,Y),writeq(f(X,Y)),nl,X=5");
                PlAssert("tc3:-foo3(X,Y,Z),Z,writeln(f(X,Y,Z)),X=5");
            }

#if USE_IKVM
            ClassFile.ThrowFormatErrors = false;
            libpl.NoToString = true;
            //SafelyRun((() => PlCall("jpl0")));            
            //SafelyRun((() => DoQuery(new Query(new jpl.Atom("jpl0")))));
            libpl.NoToString = false;
            ClassFile.ThrowFormatErrors = true;
#endif
            if (args0.Length > 0)
            {
                int i = 0;
                foreach (var s in args0)
                {
                    if (s == "-f")
                    {
                        string s1 = args0[i + 1];
                        args0[i + 1] = "['" + s1 + "']";
                        continue;
                    }
                    PlCall(s);
                    i++;
                }
            }
            if (!JplDisabled)
            {
#if USE_IKVM
                var run = new jpl.Atom("prolog");
                while (!IsHalted) SafelyRun(() => DoQuery(new jpl.Query(run)));
#endif
            }
            else
            {
                if (!PlCsDisabled)
                    // loops on exception
                    while (!SafelyRun(() => libpl.PL_toplevel())) ;
            }



            ConsoleTrace("press enter to exit");
            Console.ReadLine();
            SafelyRun(() => PlEngine.PlCleanup());

            ConsoleTrace("finshed!");


        }
Exemple #2
0
        //[MTAThread]
        public static void Main(string[] args0)
        {
            PingThreadFactories();
            bool demo = false;

            SetupProlog();

            if (demo)
            {
                DoQuery("asserta(fff(1))");
                DoQuery("asserta(fff(9))");
                DoQuery("nl");
                DoQuery("flush");

                PlAssert("father(martin, inka)");
                if (!PlCsDisabled)
                {
                    PlQuery.PlCall("assert(father(uwe, gloria))");
                    PlQuery.PlCall("assert(father(uwe, melanie))");
                    PlQuery.PlCall("assert(father(uwe, ayala))");
                    using (PlQuery q = new PlQuery("father(P, C), atomic_list_concat([P,' is_father_of ',C], L)"))
                    {
                        foreach (PlTermV v in q.Solutions)
                        {
                            ConsoleTrace(ToCSString(v));
                        }

                        foreach (PlQueryVariables v in q.SolutionVariables)
                        {
                            ConsoleTrace(v["L"].ToString());
                        }


                        ConsoleTrace("all child's from uwe:");
                        q.Variables["P"].Unify("uwe");
                        foreach (PlQueryVariables v in q.SolutionVariables)
                        {
                            ConsoleTrace(v["C"].ToString());
                        }
                    }
                    //PlQuery.PlCall("ensure_loaded(library(thread_util))");
                    //Warning: [Thread 2] Thread running "thread_run_interactor" died on exception: thread_util:attach_console/0: Undefined procedure: thread_util:win_open_console/5
                    //PlQuery.PlCall("interactor");
                    //Delegate Foo0 = foo0;
                    RegisterPLCSForeigns();
                }

                PlAssert("tc2:-foo2(X,Y),writeq(f(X,Y)),nl,X=5");
                PlAssert("tc3:-foo3(X,Y,Z),Z,writeln(f(X,Y,Z)),X=5");
            }

#if USE_IKVM
            ClassFile.ThrowFormatErrors = false;
            libpl.NoToString            = true;
            //SafelyRun((() => PlCall("jpl0")));
            //SafelyRun((() => DoQuery(new Query(new jpl.Atom("jpl0")))));
            libpl.NoToString            = false;
            ClassFile.ThrowFormatErrors = true;
#endif
            if (args0.Length > 0)
            {
                int i = 0;
                foreach (var s in args0)
                {
                    if (s == "-f")
                    {
                        string s1 = args0[i + 1];
                        args0[i + 1] = "['" + s1 + "']";
                        continue;
                    }
                    PlCall(s);
                    i++;
                }
            }
            if (!JplDisabled)
            {
#if USE_IKVM
                var run = new jpl.Atom("prolog");
                while (!IsHalted)
                {
                    SafelyRun(() => DoQuery(new jpl.Query(run)));
                }
#endif
            }
            else
            {
                if (!PlCsDisabled)
                {
                    // loops on exception
                    while (!SafelyRun(() => libpl.PL_toplevel()))
                    {
                        ;
                    }
                }
            }



            ConsoleTrace("press enter to exit");
            Console.ReadLine();
            SafelyRun(() => PlEngine.PlCleanup());

            ConsoleTrace("finshed!");
        }