2
votes

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.
1
Your output code is using the ECLiPSe programming language as shown in these tutorials. These logical loops are not supported in SWI-Prolog. - SND
Your program has been ocr'ed! You write n1 but this should be nl. You write\=, but it should be #\=. To run it in SWI, you will need to write Jobs ins 1..3 in place of domain(Jobs,1,3) and then you need to address the do as already indicated. - false
In any case, start with smaller examples! - false
Thanks so much for the feedback! Your help made it very clear! - Manzar

1 Answers

2
votes

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.