我目前是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.
答案 0 :(得分:1)
您的代码使用最初来自ECLiPSe的逻辑循环结构,最近也在SICStus Prolog上找到。可以从以下网站获得SWI-Prolog的(一项明显的在制品)实施方案:
https://github.com/JanWielemaker/logical-loops
首先尝试在代码之前加载它(它是一个Prolog文件)并查看是否可以运行它。