I hope some of you know Prolog.
CSC 240 : Intro do different programming languages.
Just introduced to prolog today. Assignment was to make a program with 10 facts and 3 rules. I've done that. So this isn't a do my home work question, its a curiosity--I want to be better question.
My question is:
How can I display all the associations (facts) known about a subject?
Ie:
Code:
descrip(car, big).
descrip(car, yellow).
descrip(car, ford).
.. etc.
In the interaction i want to see:
Code:
?what_do_we_know_about_the(car).
The car is big.
The car is yellow.
The car is ford.
I'm sure it has to do with a recursive call.
I've also got a problem with "what_is(Property)". It will return only the first fact it finds that matches the property. However, I want it to display all the subjects that are Property.
Heres the stuff I've got so far:
Code:
% Author: Jeremy Giberson
% Date: 4/22/2004
%uncontestable facts, for associations.
%color associations
axioms(color, red).
axioms(color, blue).
axioms(color, black).
axioms(color, white).
axioms(color, green).
%size associations
axioms(size, small).
axioms(size, medium).
axioms(size, large).
axioms(size, very_large).
%weight associations
axioms(weight, heavy).
axioms(weight, light).
object_color(box, red).
object_color(car, blue).
object_color(watch, black).
object_color(mouse, white).
object_size(box, medium).
object_size(car, large).
object_size(watch, small).
object_size(mouse, small).
object_description(box, is_square).
object_description(car, provides_transport).
object_description(watch, keeps_time).
object_description(mouse, furry_creature).
%query the fact list to see if the Object is a Property.
%Object = car, box, animal, watch, etc.
%Property = big, small, blue, red, heavy, etc.
is_the(Object, Property) :- object_color(Object, Property);
object_size(Object, Property);
object_description(Object, Property).
%querry axioms list to dertermine what a property might be.
%Value is a property, not an object. Red, big, small, furry etc. NOT car, box, watch etc.
what_is_a(Value) :- axioms(color, Value), write(Value), write(' is a color.'), nl; % a color?
axioms(size, Value), write(Value), write(' is a size.'), nl; % a size?
%..... % insert more axiom tests here
write('it is unknown what '), write(Value), write(' is.'), nl. % unknown, not define axiom
%See if there is an Object in the list of facts, that has the attribute of Property, display that object if it exists.
what_is(Property) :- is_the(Object, Property), write('The '), write(Object), write(' is '), write(Property).
%See if there is an Object in the list of facts, that has ANY '_' attribute, display so if there is.
is_there_a(Object) :- is_the(Object, _), write('There is a '), write(Object).
Hopefully Thanks in Advance