Hi i'm new to Prolog and I think i'm having trouble with the binding of variables. The question that im working off is this.
and this is what I have come up with so far:
:- dynamic lecture/1.
%teacherNames(['Paul'],[['Bsc4'],['Bsc1']], [['AI'],['Games Design']]).
teacherNames(['Paul'],['Bsc4'],['AI']).
teacherNames(['Paul'],['Bsc1'],['Games_dev']).
group(['Hsoftware'],['Bsc4'],['15']).
group(['total'],['Bsc1'],['127']).
group(['games'],['Bsc1'],['52']).
group(['software'],['Bsc1'],['35']).
group(['web'],['Bsc1'],['15']).
group(['systems'],['Bsc1'],['25']).
room(['B1041'],['32']).
room(['B2008'],['32']).
room(['A0006'],['140']).
student(['Bill Bloggs'],['s00000123'],['Bsc4']).
student(['Andera Martin'],['s00000100'],['software']).
assignRoom:-
%retract(lecture(TeachersName,TeachersGroup,TeachSubject)),
write('teachers name?'),nl,
read(TeachersName),
%teacherNames(TeachersName),nl,
write('Group for class'),nl,
read(TeachersGroup),
%write('Subject?'),nl,
%read(TeachSubject),
teacherNames(TeachersName,TeachersGroup,TeachSubject),
%GroupName == TeachersGroup,
%group(GroupName,_,_),
write('Choose Stream'),nl,
read(Stream),
write('time period for class'),nl,
read(Period),
group(Stream,_,_),
write('choose room'),nl,
read(Room),
room(Room,_),
%%assertz(lecture(GroupName,Subject)).
asserta(lecture(TeachersName,TeachersGroup,TeachSubject,Period,Room)).
my problem is that I want it that 'Paul' will only be able to teach AI to 'Bsc4' and only able to teach 'Games_dev' to 'Bsc1'. So in this case if I were to input:
assignRoom.
Paul %teachers name
Bsc4 %the group that will be going to the class
Hsoftware %the stream name
1 %the time the class will be on
B1041 %the room the class will be held in
That works but if i try to put in anything other than those values it fails. How I want it to work is that if the Group is 'Bsc4' than only Hsoftware will be true and if Group name was 'Bsc1' Hsoftware would be false while software,web etc. will be true and the appropriate values will be bound to lecture.
Edit:
I changed around somethings and what i got is working alot better if i don't take user error into account (which will do for this example). the new code is in this link the problem i'm having now is the binding of the Room variable..
if i input
assignRoom.
Paul.
Bsc1.
web.
1.
A0006.
I get the results I want apart from the RoomNumber always outputs as
lecture(X,C,V,B,N,Y).
Paul %correct
Bsc1 %correct
web %correct
games_dev %correct
1 %correct
B1041 %Should be A0006
So what i'm asking now would be how do I fix the binding for the room number.
room(['B1041'],['32']).
and notroom('B1041', 32)
? Anything that is a single value doesn't need to be a list. You only need a list of you require the flexibility of allowing zero, one, or more elements. – lurker