如何查看 Prolog 查询的详细顺序(执行)? [英] How do I see a detailed order (execution) for a Prolog query?

查看:53
本文介绍了如何查看 Prolog 查询的详细顺序(执行)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有这个 Prolog 程序:

loves(vincent, mia).喜欢(马塞勒斯,米娅).嫉妒(A,B): - 喜欢(A,C),喜欢(B,C).

使用查询 jealous(A,B). 我对 Prolog 很陌生,我想知道如何才能看到程序运行的确切顺序并采取其这个查询的方法?我曾尝试使用 trace, permit(A,B). 命令,但它只给了我:

没有更详细的解决方案吗?:/

解决方案

你见过

享受.


第 10 步(共 49 步)后的屏幕截图.

所有步骤后给出的屏幕截图示例.


Prolog Visualizer 使用稍微非标准的方式输入查询,通过以问号 (?) 结束查询,例如

嫉妒(A,B)?

如果您在左侧的输入区域发布查询,您将收到一个错误,例如

您示例中 Prolog Visualizer 的输入是

loves(vincent, mia).喜欢(马塞勒斯,米娅).嫉妒(A,B): - 喜欢(A,C),喜欢(B,C).嫉妒(A,B)?

当 Prolog Visualizer 完成您的示例时,请注意右侧以绿色显示的四个结果


如果您正在使用 SWI-Prolog 并且在您了解 句法统一回溯 并编写更高级的代码,您会发现这很有用:

SWI Prolog 图形调试器概述


有关其他有用的 Prolog 参考,请参阅:有用的 Prolog 参考

Let's say I have this Prolog program:

loves(vincent, mia).
loves(marcellus, mia).
jealous(A, B) :- loves(A, C), loves(B, C).

With query jealous(A,B). I'm very new to Prolog and I'd like to know how is it possible to see the exact order the program will be running and taking its ways for this query? I have tried using trace, jealous(A,B). command but it has only given me that:

Isn't there any more detailed solution for that? :/

解决方案

Have you seen the Prolog Visualizer?

When you get to the page be sure to click on the icons in the upper right to learn more.

Enjoy.


Screenshot after step 10 of 49.

Screenshot for example given after all steps.


The Prolog Visualizer uses a slightly nonstandard way to enter a query by ending the query with a question mark (?), e.g.

jealous(A,B)?

If you do not post a query in the input area on the left you will receive an error, e.g.

The input for the Prolog Visualizer for your example is

loves(vincent, mia).
loves(marcellus, mia).
jealous(A, B) :- loves(A, C), loves(B, C).
jealous(A,B)?

When the Prolog Visualizer completes your example, notice the four results in green on the right


If you are using SWI-Prolog and after you understand syntactic unification, backtracking and write more advanced code you will find this of use:

Overview of the SWI Prolog Graphical Debugger


For other useful Prolog references see: Useful Prolog references

这篇关于如何查看 Prolog 查询的详细顺序(执行)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆