![]() |
![]() |
|
home—info—lectures—exams—hws—archive
% D.Daugherty cover: % - vars vs constants % - predicates, not procedures or functions % Data: female(alice). male(bob). male(charlie). female(dee). male(ethan). % (A) Find dance partners -- one man, one woman: partner(A,B) :- male(A), female(B). partner(A,B) :- female(A), male(B). % Try: partner(alice,bob). partner(bob,alice). partner(bob,X). partner(X,bob). partner(X,Y). % (B) Find drinking partners -- both with a common preference: drinks(alice,gin). drinks(alice,martini). drinks(bob,soda). drinks(charlie,soda). drinks(charlie,whiskey). drinks(charlie,martini). drinks(ethan,water). drinkWith_v1(A,B,Drnk) :- drinks(A,Drnk), drinks(B,Drnk). % % Close, but not quite. % Note that we'll have somebody drinking with themselves. % Fix with '/==': drinkWith(A,B,Drnk) :- drinks(A,Drnk), drinks(B,Drnk), A /== B. % No fundamental difference between facts and rules; % a fact is just a rule with no variables. % drinks(charlie,X). % % Charlie should join AA; he drinks anything. % [Including other people?!] % It's weird to name a variable which we never use; % the special variable `_` can be used. % drinks(charlie,_). % % Underscore is special because even if you mention it % two or more times, it can match two *different* values: % twoNonTeaTotalers(A,B) :- drinkWith(A,_), drinkWith(B,_). % A and B may not drink the same thing % (but they both drink *something*, unlike dee.)
home—info—lectures—exams—hws—archive
©2009, Ian Barland, Radford University Last modified 2009.Nov.06 (Fri) |
Please mail any suggestions (incl. typos, broken links) to ibarland ![]() |
![]() |