I'm new to Prolog and I'm struggling to make headway with this problem.
I'd like to construct a list of levels a given teacher is assigned for a particular result. Then, I would like to count the discrete number of levels that appear. Obviously, the append()
predicates I have below are total nonsense but they're there to show my general line of approach (and how ignorant I am of how it's all supposed to work). I've tried many iterations but I'm shooting in the dark with this.
Thanks!
var program =
`:- use_module(library(lists)).
teacher_level(mike,a1).
teacher_level(mike,a2).
teacher_level(mike,b1).
teacher_level(phil,b1).
teacher_level(phil,b2).
teacher_level(phil,c1).
append([], List2, Result) :-
Result = List2,
!.
append(List1, List2, Result) :-
List1 = [Head1 | Tail1],
Result = [HeadR | TailR],
Head1 = HeadR,
append(Tail1, List2, TailR).
append(L,List):-
append([L],_,List).
table([[T1,L1],[T2,L2],[T3,L3],[T4,L4]],List):-
teacher_level(T1,L1),
teacher_level(T2,L2),
teacher_level(T3,L3),
teacher_level(T4,L4),
append([L],List):-
teacher_level(mike,L).
`
session.consult( program );
session.query('table([[T1,L1],[T2,L2],[T3,L3],[T4,L4]],List).')