【问题标题】:Prolog not printing statementsProlog 不打印语句
【发布时间】:2011-09-13 17:52:31
【问题描述】:

我在 prolog 中尝试了这个回文程序,逻辑有效,但写入操作无效。那么代码中的问题是什么?

palin(List1):- findrev(List1,[],List2), 比较(列表 1,列表 2)。

findrev([],List1,List1).

findrev([X|Tail],List1,List2):-
    findrev(Tail,[X|List1],List2).

compare([],[]):-
    write("\nList is Palindrome").

compare([X|List1],[X|List2]):-
    compare(List1,List2).

compare([X|List1],[Y|List2]):-
    write("\nList is not Palindrome").

【问题讨论】:

    标签: prolog palindrome


    【解决方案1】:

    它对我有用。我使用 SWI 序言。并尝试将 " 替换为 '。因为 "Something" 会将其打印为数字列表,而不是字符串。

    【讨论】: