users-prolog
[Top][All Lists]
Advanced

[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

Abhinav-Bhardwaj,

Your program is perfectly correct, this is how you represent "OR" in
PROLOG.
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
address@hidden


-----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..


Hi,
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,
        leave_granted(Emp),
        write('-'), write(Emp), nl,
        fail.

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

yes
?- leave_granted(abhinav).

yes
?- leave_report.

leave may be granted to following employees:-
-raman
-raman
-abhinav
no
==================
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,
Abhinav





_______________________________________________
Users-prolog mailing list
address@hidden
http://mail.gnu.org/mailman/listinfo/users-prolog




reply via email to

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