MinasTirith
Programmer
?Hey guys,
Im working on a family structure file tutorial and I am trying to sort a list using a bubble sort in descending order of salary. I have to firstly find all the person structures in the file whose salary are between 15000 & 35000 inclusive. Then sort them by salary and print them out.
The family structure I am using is:
My code is:
I keep getting a syntax error just below the passes_test predicate. Could someone point me in the right direction as to where I am going wrong? Im really confused on this one.
Thanks
MT
Im working on a family structure file tutorial and I am trying to sort a list using a bubble sort in descending order of salary. I have to firstly find all the person structures in the file whose salary are between 15000 & 35000 inclusive. Then sort them by salary and print them out.
The family structure I am using is:
Code:
family(
person(alan,sartre,date(5,may,1962),works(mopper-ups,15000)),
person(caitlin,sartre,date(11,october,1964),works(limolux,100000)),
[ person(yvonne,sartre,date(12,november,1991),unemployed),
person(alan_jr,sartre,date(4,august,1989),unemployed)
]
Code:
q18_get_list(List):-
findall(Person, passes_test(Person), List).
passes_test(Person):-
Person = person(Name, Surname, Dob, works(Co, Salary),
exists(Person),
Salary >= 15000,
Salary =< 35000.
Syntax Error here!!!
bubblesort(List, Sorted):-
swap(List, List1),!,
bubblesort(List1, Sorted).
bubblesort(Sorted, Sorted).
swap([X,Y|Rest], [Y,X|Rest]):-
X<Y,
swap([Z|Rest], [Z,Rest1]).
print_list:-
nl,nl,
mylist(List),
write_out(List).
write_out([Head|Tail]):-
write(Head),
nl,
write_out(Tail).
write_out([]):-
nl,nl.
Thanks
MT