在 Prolog 中断言数字谓词 [英] Assert numeric predicates in Prolog

查看:48
本文介绍了在 Prolog 中断言数字谓词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Prolog 中是否有可能断言代表数字的事实?例如,我想使用谓词 distance/2 并断言像 distance(town1, city2) = 1200 这样的事实.

Is there a possibility in Prolog to assert facts that represent a number? For example, I would like to use a predicate distance/2 and assert facts like distance(town1, city2) = 1200.

推荐答案

distance(town1, city2) = 1200 术语是术语 '='(distance(town1) 的语法糖, city2), 1200) as (=)/2 是一个标准的 Prolog 中缀运算符.(=)/2 也是标准的统一内置谓词.在大多数 Prolog 系统中,用户不能重新定义内置谓词.因此,您不能为它们断言子句,因为这相当于重新定义谓词.Carlo 建议使用 distance/3 谓词可能是最好的解决方案.

The distance(town1, city2) = 1200 term is syntactic sugar for the term '='(distance(town1, city2), 1200) as (=)/2 is a standard Prolog infix operator. (=)/2 is also the standard unification built-in predicate. In most Prolog systems, built-in predicates cannot be redefined by the user. Thus, you cannot assert clauses for them as that would amount to redefine the predicate. Carlo's suggestion of using a distance/3 predicate is likely the best solution.

这篇关于在 Prolog 中断言数字谓词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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