Prolog中的运算符`->`是做什么的? [英] What does the operator `-->` in Prolog do?

查看:80
本文介绍了Prolog中的运算符`->`是做什么的?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

-->运算符在Prolog中做什么,它和:-有什么区别?

What does the --> operator do in Prolog and what is the difference between it and :-?

我正在使用SWI Prolog.

I'm using SWI Prolog.

推荐答案

它用于定义DCG( D 有限的 C 因劳 G rammar)规则,而不是一般谓词.有关DCG规则的很好解释,请参见本教程.

It is used to define a DCG (Definite Clause Grammar) rule as opposed to a normal predicate. See this tutorial for a very nice explanation of DCG rules.

这里有很多关于堆栈溢出的例子.请参见 DCG标签.

There are many examples here on Stack Overflow. See the DCG tag.

这是一个非常简单的解决方案,同时显示DCG和正常谓词.

Here is one very simple solution, showing both the DCG and the normal predicate.

请注意,您必须使用phrase/2phrase/3来评估DCG.确保阅读有关DCG的SWI-Prolog手册的部分 .此处记录了两个phrase谓词.

Note that you have to use phrase/2 or phrase/3 to evaluate a DCG. Make sure to read the section of the SWI-Prolog manual on DCGs. The two phrase predicates are documented there.

这篇关于Prolog中的运算符`->`是做什么的?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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