比较 Prolog 中的两个原子 [英] Compare two atoms in Prolog

查看:52
本文介绍了比较 Prolog 中的两个原子的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在学习 prolog .. 我正在使用一个名为 prol1.1.1 的编辑器我需要编写规则来比较 2 个字符串,当我给出类似的东西时

I have been learning prolog.. I'm using a editor named prol1.1.1 I need to write rule to compare 2 strings, when i give something like

rel(a1,b1).
rel(a2,b2).
rel(b2,c2).

associatedWith(X,Y,Z) :- rel(X,Y),rel(Y,Z).

?- associatedWith(X,Y,Z).

有效

但是当我付出时

?- associatedWith(X,Y,Z),X=\=Z.

我得到解析器异常

Parser exception [Should be evaluable ''a2''[7:31]] line 7:31 

我从网站上得到的是 =\= 用于数值,我无法得到比较字符串值的答案.. 谁能帮我..

what i got from websites is =\= is for numeric values, i wasn't able to get answer for comparing string values.. can anyone help me..

而且我无法获得 swi-prolog 的 gui,你也可以帮我解决这个问题吗?我需要使用 java 程序中的调用序言,并且输出必须在 java 中再次处理,任何人都可以帮助我..

and i wasn't able to get gui for swi-prolog can u please help me with that too? i need to use the call prolog from java program and the output has to be again processed in java, can anyone please help me..

推荐答案

您正在尝试比较原子,而不是字符串.无论如何,你需要 \=

You are trying to compare atoms, not strings. Anyways, you need \=

 ?- aaa = aaa.
true.

 ?- aaa \= aaa.
false.

 ?- aaa \= aab.
true.

这篇关于比较 Prolog 中的两个原子的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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