I am trying to do my homework. I have the following collection.
(defparameter *tuples*
'((has bird feathers)
(color budgie yellow)
(eats budgie seed)
(color tweetie green)
(isa tweetie budgie)
(isa budgie bird)
))
I need to make it working in the way to pass the following tests.
(inherit tuples 'tweetie 'heart-rate) => nil
(inherit tuples 'tweetie 'color) => green
(inherit tuples 'tweetie 'eats) => seeds
(inherit tuples 'tweetie 'has) => feathers
I have managed to do work if I specify the value of the tweetie for example:
(forevery (' ((isa ?b budgie) (eats budgie ?x)) *tuples*)
(format t "~&~a" #?x) #?x)
which returns seed.
but
(forevery (' ((isa ?b budgie) (eats tweetie ?x)) *tuples*)
(format t "~&~a" #?x) #?x)
returns nil, so how can I make it match it for the specified parent values
So when tested (eats tweetie ?x) should return seed and (has tweetie ?x) should return feathers.
Thanks guys.
Here’s one simple way of doing it. But in practice you will most likely use classes, or at least structs for this purpose, and they come with the functionality of “is a” relationship built-in and it is fairly robust and a complex one.
EDIT:
Below is some way to transform your input structure into a list of classes, with the benefit of later being able to use the built-in OO functionality to assess inheritance, access field (slots) etc: