Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think the problem is the 'implicit cut' in (->)/2. Try</p> <pre><code>test_arith(Passes, Failures) :- findall(P-F, (test_arith, P=1,F=0 ; P=0,F=1), Scores), summarize_scores(Scores, 0, 0, Passes, Failures). </code></pre> <p>and you'll get</p> <pre><code>?- test_arith(P,F). P = 2, F = 1. </code></pre> <p><em>edit</em></p> <p>OT, but I like when I can make the logic more compact, of course with a little help from the library. Here an equivalent definition:</p> <pre><code>test_arith(Passes, Failures) :- findall(R, (test_arith, R=1-0 ; R=0-1), Scores), aggregate(r(sum(A),sum(B)), member(A-B, Scores), r(Passes, Failures)). </code></pre> <p>and then, why to build a list to be immediately scanned?</p> <pre><code>test_arith(Passes, Failures) :- aggregate(r(sum(A),sum(B)), (test_arith, A=1,B=0 ; A=0,B=1), r(Passes, Failures)). </code></pre> <p><em>edit</em> the above code is incorrect, being unable to count failures. I was fooled by the fact that it seemed to work with the specific test case.</p> <p>With the help of @false, here is reify_call/3, a building block that could solve OP' problem (tested in SWI-Prolog, where <a href="http://www.swi-prolog.org/pldoc/doc_for?object=clause/2" rel="nofollow">clause</a>/2 is arguably extended with respect to ISO compatibility, given @false comment to question):</p> <pre><code>test_arith(Passes, Failures) :- aggregate(r(sum(T),sum(F)), reify_call(test_arith, T, F), r(Passes, Failures)). :- meta_predicate reify_call(0, -, -). reify_call(Pred, True, False) :- clause(Pred, Cl), (call(Cl) -&gt; True = 1, False = 0 ; True = 0, False = 1). </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload