2
votes

I am struggling with a question in an assignment with prolog.

So, I have the following fact database in prolog:

student(name(doe, [john]), 33332, ['CSI1120'] ).
student(name(doe, [jane]), 33336, ['CSI1120'] ).

evaluation('CSI1120', homework(1), ['Prolog', database ], 5).

mark('CSI1120', 33332, homework(1), 3.5 ).
mark('CSI1120', 33336, homework(1), 4.0 ).

My goal here is to create a predicate listAllMarks/3 such as

?- returnAllMarks('CSI1120',homework(1),L).

Returns:

L= [(33332, 3.5), (33336, 4.0)].

In order to resolve this problem, I was thinking of making use of the prolog setof/3, so I came with the following predicate.

returnAllMarks(C,H,L):- setof(L,mark(C,_,H,X),[L|X]).

This doesn't seems to work, the predicate always return false. I"m suspecting that this may be due to the fact I am using setof against a compound predicate, but I could be wrong (I'm still in the early stages of learning prolog).

Do you guys have an idea? I look at this problem from all angles, and I am stuck here.

Thank you.

1

1 Answers

2
votes

You could write something like:

returnAllMarks(C,H,L):- setof( (X,Y), mark(C,X,H,Y), L).

Example:

?- returnAllMarks('CSI1120',homework(1),L).
L = [ (33332, 3.5), (33336, 4.0)].