Reputation: 1123
I am currently building a CLips program for cell phones. I have different cell phones and thier specs. I am trying to figure out how to make defrules to sort out features such as Color. I will show what I mean below:
([phones_Class85] of Moto+X
(Battery+Life "240")
(Build+Material "Metal")
(Camera "13")
(Card+Slot "Yes")
(Color "Cream")
(FingerPrint+Scanner "No")
(Memory "16")
(Operating+System "Android")
(Price "119")
(RAM "1")
(Screen+Size "5.2")
(Water+Resistant "Yes")
(Weight "144"))
([phones_Class86] of IPhone+6
(Battery+Life "250")
(Build+Material "Metal")
(Camera "8")
(Card+Slot "No")
(Color "Gold")
(FingerPrint+Scanner "Yes")
(Memory "16")
(Operating+System "IOS")
(Price "199")
(RAM "1")
(Screen+Size "4.7")
(Water+Resistant "No")
(Weight "129"))
([phones_Class93] of IPhone+5s
(Battery+Life "250")
(Build+Material "Metal")
(Camera "8")
(Card+Slot "No")
(Color "Gold")
(FingerPrint+Scanner "Yes")
(Memory "16")
(Operating+System "IOS")
(Price "99")
(RAM "1")
(Screen+Size "4")
(Water+Resistant "No")
(Weight "112"))
As you can see I have different cell phones that have instances of different specs. There are many more but I jsut gave a few. I am trying to do something with a defrule that will allow me to print out all the phones whos Color is Gold. I am unsure of how to move through this when I have instances. Is there a way to access the different slots (Color) within the instances then go through each one checking it?
Upvotes: 0
Views: 236
Reputation: 10757
CLIPS>
(defclass Phone
(is-a USER)
(slot Battery+Life)
(slot Build+Material)
(slot Camera)
(slot Card+Slot)
(slot Color)
(slot FingerPrint+Scanner)
(slot Memory)
(slot Operating+System)
(slot Price)
(slot RAM)
(slot Screen+Size)
(slot Water+Resistant)
(slot Weight))
CLIPS>
(defclass Moto+X
(is-a Phone))
CLIPS>
(defclass IPhone
(is-a Phone))
CLIPS>
(defclass IPhone+6
(is-a IPhone))
CLIPS>
(defclass IPhone+5s
(is-a IPhone))
CLIPS>
(definstances Phones
([phones_Class85] of Moto+X
(Battery+Life "240")
(Build+Material "Metal")
(Camera "13")
(Card+Slot "Yes")
(Color "Cream")
(FingerPrint+Scanner "No")
(Memory "16")
(Operating+System "Android")
(Price "119")
(RAM "1")
(Screen+Size "5.2")
(Water+Resistant "Yes")
(Weight "144"))
([phones_Class86] of IPhone+6
(Battery+Life "250")
(Build+Material "Metal")
(Camera "8")
(Card+Slot "No")
(Color "Gold")
(FingerPrint+Scanner "Yes")
(Memory "16")
(Operating+System "IOS")
(Price "199")
(RAM "1")
(Screen+Size "4.7")
(Water+Resistant "No")
(Weight "129"))
([phones_Class93] of IPhone+5s
(Battery+Life "250")
(Build+Material "Metal")
(Camera "8")
(Card+Slot "No")
(Color "Gold")
(FingerPrint+Scanner "Yes")
(Memory "16")
(Operating+System "IOS")
(Price "99")
(RAM "1")
(Screen+Size "4")
(Water+Resistant "No")
(Weight "112")))
CLIPS>
(defrule find-gold-phones
(object (is-a Phone)
(name ?name)
(Color "Gold"))
=>
(printout t ?name " is a gold phone." crlf))
CLIPS>
(defrule find-gold-iPhones
(object (is-a IPhone)
(name ?name)
(Color "Gold"))
=>
(printout t ?name " is a gold iPhone." crlf))
CLIPS> (reset)
CLIPS> (run)
[phones_Class93] is a gold phone.
[phones_Class93] is a gold iPhone.
[phones_Class86] is a gold phone.
[phones_Class86] is a gold iPhone.
CLIPS>
Upvotes: 1