0

I have the following file with the predicate attends which symbolizes that every student attends a certain course (the first argument : Student_ID, the second argument : Course_ID).

attends(476, c216).
attends(478, c216).
attends(484, c216).
attends(487, c216).
attends(491, c216).

I want to create a predicate-function that will be as follows:

function(W1,L,E):- 
    bagof(C,attends(Y,C), L1),intersect(L1,W1,L),length(L,E).

    %W1 : Week-1 (List: contains courses that will be exams on).
    %L : List of intersection between students courses and the ones that 
    %  will be exams on that week(W1). (It is returned only for
    %  debugging, i don't actually need this
    % E : INT : Number of courses the student will be examined on the 1st week

Where W1 (Week1) will be a list with 3 courses ( e.g W1= [c216,c205,c902]) and E will be the number of courses that the student will be examined on.

The problem is that for every student there will be backtracking so i have to press ";". So for each student there is a different E. Instead what i want is to have all of these E values in one list without pressing ";" and then see how many E values are larger that 2 (>2).

false
  • 10,264
  • 13
  • 101
  • 209
DIMITRIOS
  • 305
  • 1
  • 3
  • 10
  • 2
    You may want `bagof(C,Y^attends(Y,C), L1)`. – Arndt Jonasson May 09 '18 at 13:40
  • This sums up all the E values in one integer. What i need is all E values to be in a list so i can then count how many are larger that 2. – DIMITRIOS May 09 '18 at 14:12
  • 2
    *Predicate*. Not *predicate-function*. There is no such thing as a *predicate-function*. *function* not a very good name at all for a predicate. The name should reflect the relation you're defining. It's not clear to me what this predicate does. Your comment says, *`E` : INT : Number of courses the student will be examined on the 1st week*. What student are you referring to? Or is the predicate intended to provide an aggregate result for *all* students? And if that's true, what do you want your results to look like? – lurker May 09 '18 at 15:10
  • 2
    If "function" does what you want already but you don't want to press `;` each time, then you would use `findall(E, function(W1, _, E), Es)` (assuming you don't care about `L`). – lurker May 09 '18 at 15:12
  • findall actually solved my problem. I don't care about L i just want the list of E of every student. Thank you! – DIMITRIOS May 09 '18 at 15:42

0 Answers0