views:

132

answers:

1

Hi, 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=[].  
listtran(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?

+2  A: 

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).
Max Shawabkeh