从 Prolog 中的事实打印一个值? [英] Print a value from a fact in Prolog?
本文介绍了从 Prolog 中的事实打印一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有这些事实:
champion(Real_Madrid).
second_place(Atl).
如何从 Prolog 中的查询打印Real_Madrid"字符串值,例如:
How do I print the "Real_Madrid" string value from a query in Prolog so I can say for example:
冠军(某事).
皇家马德里
有什么办法吗?
推荐答案
在 Prolog 中,如果原子以大写字母开头,则需要引号,以免与变量混淆.
In Prolog, atoms need quotes if they start by an upper-case letter so that they're not confused with variables.
在这里,你可以写:
champion('Real Madrid').
second_place('Atl').
然后是简单的查询:
?- champion(Something).
将打印所需的绑定:
Something = 'Real Madrid'.
如果需要,您可以在此处找到有关 Prolog 语法的更多信息.
这篇关于从 Prolog 中的事实打印一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文