【发布时间】:2020-05-22 09:07:20
【问题描述】:
我写了以下事实来表示管图
station(AL,[Metropolitan]).
station(BG,[Central]).
station(BR,[Victoria]).
station(BS,[Metropolitan]).
station(CL,[Central]).
station(EC,[Bakerloo]).
station(EM,[Bakerloo,Northern]).
station(EU,[Northern]).
station(FP,[Victoria]).
station(FR,[Metropolitan]).
station(KE,[Northern]).
station(KX,[Metropolitan,Victoria]).
station(LG,[Central]).
station(LS,[Central,Metropolitan]).
station(NH,[Central]).
station(OC,[Bakerloo,Central,Victoria]).
station(PA,[Bakerloo]).
station(TC,[Central,Northern]).
station(VI,[Victoria]).
station(WA,[Bakerloo]).
station(WS,[Northern,Victoria]).
我需要写一个form的谓词
station_exists(Station)
检查一个站是否存在,但我不知道如何编写规则。我尝试过类似的方法:
station_exists(Station):- station(Station,_)
但对于任何电台名称,它都会返回 true。有人可以帮忙吗?
【问题讨论】:
-
你的常量以大写字母开头,所以 Prolog 认为这些是变量而不是常量。
-
请不要通过破坏您的帖子为他人增加工作量。通过在 Stack Exchange 网络上发帖,您已在 CC BY-SA 3.0 license 下授予 Stack Exchange 分发该内容的不可撤销的权利(即无论您未来的选择如何)。根据 Stack Exchange 政策,帖子的非破坏版本是分发的版本。因此,任何破坏行为都将被撤销。如果您想了解更多关于删除帖子的信息,请参阅:How does deleting work?