问题
I am using swi- prolog with c# as front end. I want to to display whether the the query is executed or not in a mmessagebox. So i need the answer in 'true' or 'false' like it comes in prolog console. here is my code:
static void Main(string[] args)
{
Environment.SetEnvironmentVariable("SWI_HOME_DIR", @"C:\Program Files\swipl");
Environment.SetEnvironmentVariable("PATH", @"C:\Program Files\swipl");
Environment.SetEnvironmentVariable("PATH", @"C:\Program Files\swipl\bin");
string p1 = @"C:\Program Files\swipl\try9.pl";
string[] p = { "-q", "-f", p1 };
PlEngine.Initialize(p);
try
{
PlQuery q = new PlQuery("get(sam,age(26)).");
// here i need the responce of prolog engine of the above query whether true or false .
Console.ReadLine();
}
catch (PlException ex)
{
Console.WriteLine("exception handeled" + ex.Message);
}
}
回答1:
Let me state first of all that I have never used swi-prolog, so this may not be what you're looking for. But I am able to read documentation and samples... :)
I found this page: http://www.lesta.de/prolog/swiplcs/Generated/html/M_SbsSW_SwiPlCs_PlQuery__ctor.htm
And it sounds like you might want something like the following. Or at least maybe it helps get you started?
try
{
using (var q = new PlQuery("get(sam,age(26))."))
{
if (q.Solutions == null) // Not sure if this is possible?
{
Console.WriteLine("Query did not run successfully.");
}
else
{
Console.WriteLine("Query returned {0} items.", q.Solutions.Count());
}
}
}
catch (PlException ex)
{
Console.WriteLine("Exception handled: " + ex.Message);
}
Console.ReadLine();
来源:https://stackoverflow.com/questions/29634054/true-false-response-of-query-from-prolog-in-c-sharp