繁体   English   中英

true-来自C#中prolog的查询的错误响应

[英]true - false response of query from prolog in C#

我正在使用带有C#的swi-prolog作为前端。 我想在mmessagebox中显示是否执行查询。 因此,我需要“真”或“假”的答案,就像Prolog控制台中提供的一样。 这是我的代码:

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);
    }

}

首先,请允许我说一下我从未使用过swi-prolog,所以这可能不是您想要的。 但是我能够阅读文档和样本... :)

我找到了以下页面: http : //www.lesta.de/prolog/swiplcs/Generated/html/M_SbsSW_SwiPlCs_PlQuery__ctor.htm

听起来您可能想要以下内容。 或者至少可以帮助您入门?

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();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM