Code Comments
Programming Forum and web based access to our favorite programming groups.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
Post Follow-up to this messageSorry 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
Post Follow-up to this message"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.
Post Follow-up to this messagethanx - that works fine - and now I'm going to try to understand why ;-) Luigi
Post Follow-up to this messageHow do i make another question different_sex(Person1,Person2) :- ?????? Luigi
Post Follow-up to this message"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.
Post Follow-up to this messageThanx a lot - now I'm going to understand - but on last question: What is the diffrence between \== and \= ? Luigi
Post Follow-up to this message"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.
Post Follow-up to this messageStefan 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
Post Follow-up to this messagePowered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.