public static void Main(string [] args) { PrologEngine e = null; try { e = new PrologEngine (new DosIO ()); // ProcessArgs -- for batch processing. Can be left out if not used if (e.ProcessArgs (args, false)) return; SetPreferredConsoleProperties (e); Console.Title = "C#Prolog command window"; Console.WriteLine (PrologEngine.IntroText); Console.WriteLine ("\r\n--- Enter !! for command history, help for a list of all commands"); //if (Engine.ConfigSettings.InitialConsultFile != null) // set in CSProlog.exe.config // e.Consult (Engine.ConfigSettings.InitialConsultFile); // any additional initialisations while (!e.Halted) { Console.Write (e.Prompt); e.Query = ReadQuery (); // Use e.GetFirstSolution instead of the loop below if you want the first solution only. //Console.Write (e.GetFirstSolution (e.Query)); foreach (PrologEngine.ISolution s in e.SolutionIterator) { // In order to get the individual variables: //foreach (Engine.IVarValue varValue in s.VarValuesIterator) // { Console.WriteLine (varValue.Value.To<int> ()); } // or ToString () etc. Console.Write (s); if (s.IsLast || !UserWantsMore ()) break; } Console.WriteLine (); } } catch (Exception x) { Console.WriteLine ("Error while initializing Prolog Engine. Message was:\r\n{0}", x.GetBaseException ().Message + Environment.NewLine + x.StackTrace); Console.ReadLine (); } finally { if (e != null) e.PersistCommandHistory (); // cf. CSProlog.exe.config } }
void bgwExecuteQuery_DoWork(object sender, DoWorkEventArgs e) { try { pe.Query = e.Argument as string; semaMoreStop = new ManualResetEvent(false); foreach (PrologEngine.ISolution s in pe.SolutionIterator) { winIO.WriteLine("{0}{1}", s, (s.IsLast ? null : ";")); if (s.IsLast) { break; } bool stop; WaitForMoreOrStopPressed(out stop); semaMoreStop.Reset(); if (stop) { break; } } } finally { pe.PersistCommandHistory(); } }
public static void Main(string [] args) { PrologEngine e = null; try { e = new PrologEngine(new DosIO()); // ProcessArgs -- for batch processing. Can be left out if not used if (e.ProcessArgs(args, false)) { return; } SetPreferredConsoleProperties(e); Console.Title = "C#Prolog command window"; Console.WriteLine(PrologEngine.IntroText); Console.WriteLine("\r\n--- Enter !! for command history, help for a list of all commands"); //if (Engine.ConfigSettings.InitialConsultFile != null) // set in CSProlog.exe.config // e.Consult (Engine.ConfigSettings.InitialConsultFile); // any additional initialisations while (!e.Halted) { Console.Write(e.Prompt); e.Query = ReadQuery(); // Use e.GetFirstSolution instead of the loop below if you want the first solution only. //Console.Write (e.GetFirstSolution (e.Query)); foreach (PrologEngine.ISolution s in e.SolutionIterator) { // In order to get the individual variables: //foreach (Engine.IVarValue varValue in s.VarValuesIterator) // { Console.WriteLine (varValue.Value.To<int> ()); } // or ToString () etc. Console.Write(s); if (s.IsLast || !UserWantsMore()) { break; } } Console.WriteLine(); } } catch (Exception x) { Console.WriteLine("Error while initializing Prolog Engine. Message was:\r\n{0}", x.GetBaseException().Message + Environment.NewLine + x.StackTrace); Console.ReadLine(); } finally { if (e != null) { e.PersistCommandHistory(); // cf. CSProlog.exe.config } } }