Prolog 谓词参数中实例化模式指示符的含义 [英] Meaning of instantiation mode indicators in arguments of Prolog predicates

查看:67
本文介绍了Prolog 谓词参数中实例化模式指示符的含义的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看 Prolog 文档,谓词签名有时是这样写的:

Looking at Prolog documentation, predicate signatures are sometimes written as following:

foo(:Bar, +Baz, -Qux, ?Mop)

:+- 是什么? 是什么?我该如何解释它们?另外,这些是唯一存在的还是更多的?

What are :, +, - and ? for and how do I interpret them? Also, are these the only ones that exist or are there more of them?

推荐答案

在这个上下文中,那些前缀运算符代表实例化模式,即它们告诉您在调用谓词时哪些参数应该是变量或实例化.它们还会告诉您调用是否会(可能进一步)实例化参数.它们还可以用来告诉您,您正在调用的谓词将以某种方式对参数进行元解释.其中一些实例化模式是标准的,其他的取决于系统.最常见的是:

Those prefix operators, in this context, represent instantiation modes, i.e. they tell you which arguments should be variables or instantiated when calling the predicate. They also tell you if an argument will be (possibly further) instantiated by the call. They can also be used to tell you that an argument is going to be meta-interpreted in some way by the predicate you're calling. Some of these instantiation modes are standard, other depend on the system. The most usual are:

- - 参数应该是未绑定的(可能是输出参数)

- - the argument should be unbound (likely output argument)

+ - 参数应该被绑定(输入参数)

+ - the argument should be bound (input argument)

? - 参数可以绑定或未绑定

? - the argument can be either bound or unbound

@ - 参数不会被调用进一步实例化

@ - the argument will not be further instantiated by the call

: - 参数将以某种方式进行元解释(通常是模棱两可的)

: - the argument will be meta-interpreted in some way (often ambiguous)

0 - 参数将被解释为目标并如此调用

0 - the argument will be interpreted as goal and called as such

N - 其中 N 是自然数;该参数将被解释为一个闭包,该闭包将由 N 个附加参数组成,以构造一个将被调用的目标

N - where N is natural number; the argument will be interpreted as a closure that will be composed with N additional arguments to construct a goal that will be called

不同的系统提供其他或不同的实例化模式.例如,用于在调用谓词时声明参数应为基础,或用于声明参数应为谓词指示符或将被解释为语法规则体.您需要参考您使用的 Prolog 系统的文档以了解详细信息.

Different systems provide other or different instantiation modes. For example, for stating that an argument should be ground when calling a predicate, or for stating that an argument should be a predicate indicator or that will be interpreted as a grammar rule body. You will need to refer to the documentation of the Prolog system you're using for the details.

这篇关于Prolog 谓词参数中实例化模式指示符的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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