0

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

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). 
4

1 回答 1

1

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

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

map( _ , []     , []     ) .
map( G , [X|Xs] , [Y|Ys] ) :-
  call(G,X,Y)  ,
  map(G,Xs,Ys) .
于 2015-01-15T18:49:16.483 回答