Reputation: 21
I'm currently a beginner in Prolog and I've been running into a operator error. According to the compiler, it has to do something with the "do statement." Any guidance would be very appreciative. Thank you.
:-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.
Upvotes: 2
Views: 427
Reputation: 18663
Your code uses the logical loops constructs originally from ECLiPSe and more recently also found on SICStus Prolog. There's is (an apparent work-in-progress) implementation for SWI-Prolog available from:
https://github.com/JanWielemaker/logical-loops
Try load it first (it's a single Prolog file) before your code and see if you can run it.
Upvotes: 2