Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

Re: Duplicate results after queries
"Swartz" <swartz@inbox.ru> wrote in message news:<10r0bs9tccfri71@corp.supernews.com>...[co
lor=darkred]
> Hi all.
>
> Writing a simple example:
>
> % parent(X,Y) => X is parent of Y
> parent(bob,billy).
> parent(pam,billy).
> parent(bob,mandy).
> parent(pam,mandy).
> sibling(X,Y) :- parent(Z,X), parent(Z,Y), X \== Y.
>
> Any queries like the one below end up with duplicate answers.
>
> Ex:
> | ?- sibling(X,billy).
> X = mandy ?
> X = mandy
> no
>
> I understand why it happens but do not know prolog well enough to prevent
> it? Any suggestions?
>
> Thanks in advance.[/color]

Hi,

"cut" is the standard way to skip overload of solutions.

By example:

acommonparent(LX,LY) :-
member(X,LX),
member(Y,LY), !.

sibling(X,Y) :-
setof(A,parent(A,X),LX),
setof(B,parent(B,Y),LY),
acommonparent(LX,LY).

(you can play around this concept to adapt it to your requirement).

Report this thread to moderator Post Follow-up to this message
Old Post
Pere Montolio
12-07-04 09:13 AM


Re: Duplicate results after queries
Pere Montolio wrote:

>
> acommonparent(LX,LY) :-
> member(X,LX),
> member(Y,LY), !.

I think you mean:

acommonparent(LX,LY) :-
member(X,LX),
member(X,LY),  % watch out!
!.


The advantage of the solution I posted was its indepedence of the
definition of sibling/2. If you for example change sibling/2 so that two
entities are siblings of they share *both* their parents instead of only
one, you can still use my solution, whereas yours would require more
complicated modifications because you have to think in terms of sets
instead of single entities.

Best regards,
Markus.

Report this thread to moderator Post Follow-up to this message
Old Post
Markus Triska
12-07-04 09:13 AM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Prolog archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 07:17 AM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.