开发者

Illegal start of term in Prolog

I'm trying to write some predicates to solve the following task (learnprolognow.com)

Suppose we are given a knowledge base with the following facts:

tran(eins,one).
tran(zwei,two).
tran(drei,three).
tran(vier,four).
tran(fuenf,five).
tran(sechs,six).
tran(sieben,seven).
tran(acht,eight).
tran(neun,nine).

Write a predicate listtran(G,E) which translates a list of German number words to the corresponding list of English number words. For example:

listtran([eins,neun,zwei],X).

should give:

X = [one,nine,two].

I've written:

listtran(G,E):- G=[], E=[].  
li开发者_如何学Gosttran(G,E):- G=[First|T], tran(First, Mean), listtran(T, Eng), E = [Mean|Eng).

But I get the error: "illegal start of term" when compiling. Any suggestions?


The last bracket in your last line should be a square one.

Also, you might want to make use of Prolog's pattern matching:

listtran([], []).
listtran([First|T], [Mean|EngT]):-
   tran(First, Mean),
   listtran(T, EngT).
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜