1
我目前是Prolog的初學者,我一直在遇到一個操作錯誤。根據編譯器,它必須對「do語句」做些什麼。任何指導都將非常感激。謝謝。語法錯誤:操作員期望(做語句)
:-use_module(library(clpfd)).
:-use_module(library(lists)).
go :-
Mary = 1,
John = 2,
Jim = 3,
Persons = [Mary, John, Jim],
Jobs = [Gardener, Veteriarian, Dishwasher, Nurse, MathTeacher, BiologyTutor],
domain(Jobs,1,3),
% This means that each person holds two jobs
global_cardinality(Jobs,[1-2,2-2,3-2]),
%nurse went out with the veteriarian last night
Nurse \= Veteriarian,
%mary is friends with the biology tutor but she stayed home last night
Mary \= BiologyTeacher, Mary \= Nurse, Mary \= Veteriarian,
%jim likes animals but doesn't do good in math and dropped out of college
Veteriarian = Jim, Jim \= MathTeacher, Jim \= BiologyTutor, Jim \= Nurse,
%jim doen't know the gardener
Gardener \= Jim, Mary = Gardener,
%Mary and the biology teacher used to be married
BiologyTeacher = John,
%search
labeling([],Jobs),
%output
write(Jobs),n1,
PersonsStr = ['Mary', 'John', 'Jim'],
JobStr = ['Gardener', 'Veteriarian', 'Dishwasher', 'Nurse', 'MathTeacher', 'BiologyTutor'],
( foreach(J, Jobs),
foreach(JS, JobStr),
param(PersonsStr, Persons) do
(foreach(P, Persons),
foreach(PS, PersonsStr),
param(J,JS) do
P == J -> format('~w\t~w'[JS,PS]) ;
true
),
n1
),
fd_statistics.
您的輸出代碼使用ECLiPSe編程語言,如[這些教程](http://eclipseclp.org/doc/tutorial/tutorial025.html)中所示。這些邏輯循環在SWI-Prolog中不受支持。 – SND
您的程序已被發現!你寫'n1',但這應該是'nl'。你寫'\ =',但它應該是'#\ ='。爲了在SWI中運行它,你需要寫'Jobs in 1..3'來代替'domain(Jobs,1,3)',然後你需要按照已經指出的那樣來處理'do'。 – false
無論如何,從更小的例子開始! – false