Illegal start of term in Prolog

I am trying to write some predicates to solve the following problem (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) that translates a list of German number words into the corresponding list of English words. For instance:

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

should give:

 X = [one,nine,two]. 

I wrote:

 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 term start" when compiling. Any suggestions?

+4
source share
1 answer

The last parenthesis in your last line should be square.

Alternatively, you can use the Prolog pattern matching:

 listtran([], []). listtran([First|T], [Mean|EngT]):- tran(First, Mean), listtran(T, EngT). 
+3
source

Source: https://habr.com/ru/post/1300986/


All Articles