[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: representing 'OR' condition in Prolog.. (removing duplicates).

From: Robert Wolf
Subject: RE: representing 'OR' condition in Prolog.. (removing duplicates).
Date: Fri, 1 Nov 2002 09:00:13 +1030


Your program is perfectly correct, this is how you represent "OR" in
To remove duplicates insert negative conditions, something like:

        leave_granted(Emp) :-
                employee_status(Emp, permanent),
                NOT (performance (Emp, satisfactory)).
        leave_granted(Emp) :-
                performance(Emp, satisfactory),
                NOT (employee_status (Emp, permanent)).

The first condition will "generate" employees, the second will filter
them out.
To make your program absolutely "beautifull" insert second clause to
your report.
Something like:
        leave_report :- write ('No (more) answers.').
This will prevent your report from the "general failure" at the end.

Best regards and "happy prologing"...

Robert P. Wolf

-----Original Message-----
From: Abhinav-Bhardwaj [mailto:address@hidden
Sent: Thursday, 31 October 2002 5:07 PM
To: address@hidden
Subject: representing 'OR' condition in Prolog..

I want to know something in general about prolog . I want to know that
how do I represent an 'OR' condition in prolog.
For eg:- I want to define a leave rule saying that an employee can be
granted a leave if - employee is a Permanent employee, OR
          -  employee's performance is satisfactory.

leave_granted(Emp) :- employee_status(Emp, permanent).
leave_granted(Emp) :- performance(Emp, satisfactory).

employee_status( raman, permanent).
employee_status( abhinav, temporary).

performance( raman, satisfactory).
performance( abhinav, satisfactory).

leave_report :-
        nl, write('leave may be granted to following employees:-'), nl,
        write('-'), write(Emp), nl,

Here is a sample output:
?- leave_granted(raman).

?- leave_granted(abhinav).

?- leave_report.

leave may be granted to following employees:-
Now my question is:
1) Is this a correct way to represent the rule ?
2) The 'leave_report' displays the name 'raman' twice , and what I want
is a list of unique names of employees that can be granted leave.

thanks and regards,

Users-prolog mailing list

reply via email to

[Prev in Thread] Current Thread [Next in Thread]