在 Prolog 中打印一个事实的值? [英] Print a value from a fact in Prolog?

查看:9
本文介绍了在 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 语法的信息.

If needed, you can find more information about Prolog syntax here.

这篇关于在 Prolog 中打印一个事实的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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