recursion - Searching for a value in a list with Prolog -
recursion - Searching for a value in a list with Prolog -
i'm writing recursive function in prolog check if course of study (crs) in semester (sem, list) has pre requisite course of study met in prior (a list). there 2 examples of course of study in sec block of code. when runs fails csse1001 (which has no prerequisite), when should homecoming true has search nothing. missing?
checksem(prior,[]). checksem(prior,sem):- [crs|tail] = sem, member(pre(crs,list),prior), checksem(prior,tail).
course:
parta(comp3506). lvl3(comp3506). s1(comp3506). pre(comp3506,[csse2002]). parta(csse1001). lvl1(csse1001). s1(csse1001). pre(csse1001,[]).
you did not give illustration query checksem/2
guess first argument prior
list of courses. think should check if name of course of study fellow member in prior
, not pre(crs, list)
. second, have list of prerequisites , not one, should check of them members in prior.
checksem(_,[]). checksem(prior,[crs|tail]):- pre(crs, list), \+ (member(prereq, list), \+ member(prereq, prior)), checksem(prior,tail).
this goal \+ (member(prereq, list), \+ member(prereq, prior))
satisfied if there exists no course of study prereq
fellow member of list
, it's not fellow member of prior
.
list recursion prolog member
Comments
Post a Comment