2016-07-29 65 views
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. 
+2

您的輸出代碼使用ECLiPSe編程語言,如[這些教程](http://eclipseclp.org/doc/tutorial/tutorial025.html)中所示。這些邏輯循環在SWI-Prolog中不受支持。 – SND

+2

您的程序已被發現!你寫'n1',但這應該是'nl'。你寫'\ =',但它應該是'#\ ='。爲了在SWI中運行它,你需要寫'Jobs in 1..3'來代替'domain(Jobs,1,3)',然後你需要按照已經指出的那樣來處理'do'。 – false

+2

無論如何,從更小的例子開始! – false

回答

1

您的代碼使用的邏輯循環從最初ECLiPSe構建以及最近還發現SICStus Prolog。還有的是(一個明顯的工作正在進行中)實現SWI-Prolog的可從以下

https://github.com/JanWielemaker/logical-loops

試試你的代碼之前先加載它(這是一個單一的Prolog文件),看看是否可以運行它。