Prolog操作员预期的错误

时间:2015-01-15 15:43:44

标签: prolog syntax-error meta-predicate

我在堆栈溢出时搜索了Prolog运算符预期的错误问题,但是我无法识别出错误:

4:26: Syntax error: Operator expected
% 3.pl compiled 0.00 sec, 3 clauses

代码很简单:

inc(N,R) :-
  R is N + 1. % Simple code to increment a number.

mapcar( F , []    , []     ).  % Base case 
mapcar( F , [H|T] ,[RH|RT] ) :- % Increment head and put it in Result Head and Recurse for Tail
  F(H,RH),
  mapcar(F,T,RT). 

1 个答案:

答案 0 :(得分:1)

这实际上是这个问题的重复:Prolog map procedure that applies predicate to list elements

但我会咬人。你可以简单地说,正如所建议的那样:

map( _ , []     , []     ) .
map( G , [X|Xs] , [Y|Ys] ) :-
  call(G,X,Y)  ,
  map(G,Xs,Ys) .