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

Newbie-Question
Hi, I'm a very beginner in prolog - so please be patient

human(man,john).
human(man,ben).

same_sex(person1,person2) :- human(X,person1) ==
human(X,person2).

This will cause a no for
same_sex(john,ben).

What is wrong and what should I learn/read about?

thanx
Luigi Motorra

Report this thread to moderator Post Follow-up to this message
Old Post
Luigi Motorra
09-06-04 09:02 PM


Re: Newbie-Question
Sorry about the simple failure with big and small letters - thats not my
problem. I meant

human(man,john).

human(man,ben).

same_sex(Person1,Person2) :- human(X,Person1) == human(X,Person2).

Luigi


Report this thread to moderator Post Follow-up to this message
Old Post
Luigi Motorra
09-06-04 09:02 PM


Re: Newbie-Question
"Luigi Motorra" <Luigi_MotorraDELETETHIS@gmx.net> writes:

> same_sex(Person1,Person2) :- human(X,Person1) == human(X,Person2).

You don't want to compare facts but to fulfill two facts at the
same time -- that's a logical and. Try this:

same_sex(Person1,Person2) :-
human(X,Person1),
human(X,Person2).

--
Stefan.

Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Nobis
09-06-04 09:02 PM


Re: Newbie-Question
thanx - that works fine - and now I'm going to try to understand why ;-)

Luigi


Report this thread to moderator Post Follow-up to this message
Old Post
Luigi Motorra
09-07-04 02:07 PM


Re: Newbie-Question
How do i make another question

different_sex(Person1,Person2) :- ??????

Luigi

Report this thread to moderator Post Follow-up to this message
Old Post
Luigi Motorra
09-07-04 02:07 PM


Re: Newbie-Question
"Luigi Motorra" <Luigi_MotorraDELETETHIS@gmx.net> writes:

> How do i make another question

> different_sex(Person1,Person2) :- ??????

I'm no expert, so i don't know if this is a good solution, but it
works:

different_sex(Person1, Person2) :-
human(X, Person1),
human(Y, Person2),
X \== Y.

Prolog tries to unify the variables and then tests, if X and Y are
not both bound to the same value.

You can read it like this:

If there is a person with sex X and another person (maybe quite
the same as the first) with sex Y and X and Y are different, then
the predicate different_sex evaluates to true.

--
Stefan.

Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Nobis
09-07-04 02:07 PM


Re: Newbie-Question
Thanx a lot - now I'm going to understand - but on last question:

What is the diffrence between \== and \= ?

Luigi

Report this thread to moderator Post Follow-up to this message
Old Post
Luigi Motorra
09-07-04 09:10 PM


Re: Newbie-Question
"Luigi Motorra" <Luigi_MotorraDELETETHIS@gmx.net> writes:

> Thanx a lot - now I'm going to understand - but on last question:

> What is the diffrence between \== and \= ?

IIRC = or \= tries to bind variables (-> unifying), but == or \==
does not (needed e.g. for arithmetic). So in the last example \=
would have worked, too.

--
Stefan.

Report this thread to moderator Post Follow-up to this message
Old Post
Stefan Nobis
09-08-04 02:01 PM


Re: Newbie-Question
Stefan Nobis <stefan@snobis.de> wrote:
> "Luigi Motorra" <Luigi_MotorraDELETETHIS@gmx.net> writes: 

> IIRC = or \= tries to bind variables (-> unifying), but == or \==
> does not (needed e.g. for arithmetic). So in the last example \=
> would have worked, too.

\= 		should not "end up" binding anything, of course. ;)

== and \== 	simply test for equality (in-) of general terms "literally".

=:= and =\= 	test numberical values for equality (in-) after
arguments are interpreted  as arith expressions.

So given X and Y and unbound variables

X = Y		because all unbound variables are "equal"
(as a side-effect X and Y will not refer to the same value
for the rest -- "to the right" in the current clause).

X == Y	 fails	because X and Y are not literally the same unbound variable
(no side effects -- X and Y can still eb bound differently
in the remainder of the clause).

X \= Y	fails	because X and Y could be bound to the same value
(no S.E.).

X \== Y succeeds	because X and Y are not literally the same
(no S.E.).

X =:= Y		gets an error because nothing is instantiated.

X =\= Y		gets an error because nothing is instantiated.

--
kym@kym.massbus.org

Report this thread to moderator Post Follow-up to this message
Old Post
russell kym horsell
09-09-04 08:56 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 05:01 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.