Prolog:运营商预期

时间:2012-03-23 15:22:20

标签: prolog

我在以下两条规则的末尾收到“操作员预期”错误,但我无法理解原因。

testDrivenChecking :-
%Stores all the methods of the projet which are tested by a unit test 
findall(allTestedMethods, 
    (create(allTestMethods, 'method', _, _), 
        addProperty(allTestMethods, 'annotation', 'Test', _, _), %Method created and ensures that it's a test.
        not(delete(allTestMethods, 'method', _, _)), %The test should not be deleted
        addReference(allTestMethods, 'calls', allTestedMethods, _, _),
        not(remReference(allTestMethods, 'calls', allTestedMethods, _, _))), %Ensures that the test keep testing the method
    allTestedMethodsList),
list_to_set(allTestedMethodsList, allTestedMethodSet),

%Stores all the methods of the project which are not tests or main
findall(allMethods, 
    (create(allMethods, 'method', _, _),
        not(addProperty(allMethods, 'annotation', 'Test', _, _)), 
        not(addProperty(allMethods, 'name', 'main', _, _)), 
    allMethodsList),
list_to_set(allMethodsList, allMethodsSet),  

%Intersection gives the set of methods which are not tested in restMethods
intersection(allTestedMethodSet, allMethodSet, restMethods),

%Gives the lengths of each set
length(allTestedMethodSet, LengthTest), 
length(allMethodSet, LengthMethods),
length(restMethods, LengthRest). 

我已经找了几个小时,但我真的找不到为什么我不工作。

2 个答案:

答案 0 :(得分:2)

此:

findall(allMethods, 
        (create(allMethods, 'method', _, _),
         not(addProperty(allMethods, 'annotation', 'Test', _, _)), 
         not(addProperty(allMethods, 'name', 'main', _, _)), 
        allMethodsList),

应该是:

findall(allMethods, 
        (create(allMethods, 'method', _, _),
         not(addProperty(allMethods, 'annotation', 'Test', _, _)), 
         not(addProperty(allMethods, 'name', 'main', _, _))), 
        allMethodsList),

请注意第四行中的附加右括号。

答案 1 :(得分:0)

另请注意,not/1是过去的遗物。请考虑使用标准的(\+)/1内置谓词。