%trace
domains
child_details = child(string,integer)
children = child_details*
database
employee(integer,string,string,children)
predicates
print_employee(integer)
insert_details
find_children(children,integer)
clauses
insert_details:-
retractall(employee(_,_,_,_)),
assert(employee(1,emp1,emp3,[child(e1child1,10), child(e1child2,20)])),
assert(employee(2,emp2,emp4,[child(e2child2,20)])),
assert(employee(3,emp5,emp6,[child(e2child3,10)])).
find_children([],ChildAge):- fail.
find_children([child(Name,Age)|Tail],ChildAge):-
Age = ChildAge.
find_children([child(Name,Age)|Tail],ChildAge):-
Age <> ChildAge,
find_children(Tail,ChildAge).
print_employee(ChildAge):-
employee(EmpNo,EmpName,SpouseName,ChildrenList),
find_children(ChildrenList,ChildAge),
write(EmpName),
nl,
fail.
print_employee(ChildAge).
goal
clearwindow,
makewindow(1,2,3,"Employee Children",0,0,25,80),
insert_details,
write("Following are the employees whose children are of age 10"),
nl,
print_employee(10).
Output
+-------------------------------Employee Children-----------------------------+
¦Following are the employees whose children are of age 10 ¦
¦emp1 ¦
¦emp5 ¦
¦ ¦
¦Press the SPACE bar ¦
¦ ¦
¦ ¦
+-----------------------------------------------------------------------------+