如何正确编译序言问题?

How to compile a prolog question correctly?

我正在处理序言问题,需要一些帮助。

/*Write a predicate listtran(L,E) which translates a list of Latin number words 
 * to the corresponding list of English number words. */

%% predicate
listtran(L,E).

%% clauses
tran(unus,one).
tran(duo,two).
tran(tres,three).
tran(quattuor,four).
tran(quinque,five).
tran(sex,six).
tran(septem,seven).
tran(octo,eight).
tran(novem,nine).

%% rules
% base case: empty list
listtran([], []).
% inductive cases: 
listtran([L | T0], [E | T1]) :-
  tran(L, E), % translate the head of the list
  listtran(T0, T1). % translate the tail of the list, using recursion

谓词和查询需要写什么来测试:

?- listtran([unus,novem,duo],X).
should give:
X = [one,nine,two].

?- listtran(X,[one,seven,six,two]).
it should return:
X = [unus,septem,sex,duo].

此外,如何避免错误消息:

Clauses of listtran/2 are not together in the source-file

谢谢!

这是一个不连续的谓词错误。

Prolog 抱怨谓词的所有子句没有在一个地方定义。您应该在开始时删除 listtrans(L, E).(为什么它还在那里?),其余的应该可以正常工作。

错误解释: