COOL: Classes vs facts?

55 views
Skip to first unread message

Jonas Rundberg

unread,
Nov 9, 2023, 11:22:09 AM11/9/23
to CLIPSESG
Hi,

Is there any fundamental difference (or implications) of using classes/instances over deftemplate and slots?

I want to build a rule based AI for a computer game where I have several animals of the same kind. Rules define how they interact with other animals and other objects. In traditional OO this would be a good fit for an Animal class. Are there any arguments against using that approach in CLIPS?

How do I achieve the same effect as retracting a fact when using classes? By setting the specific slot to nil?

Thanks!

CLIPS Support

unread,
Nov 9, 2023, 2:05:27 PM11/9/23
to CLIPSESG
Defclass support inheritance while deftemplates do not. Instance patterns are only triggered when a slot explicitly match in a pattern is changed, whereas any change to a fact will retrigger a fact pattern even if the slot change is not present in a pattern. The creation/deletion of instances has more associated overhead, so in many cases you'll get slightly better performance from fact instead of instances.

If you need inheritance and/or have a fair amount of OO code associated with your objects, then you'll want to use instances. If you can do without inheritance and your solution mostly involves pattern matching without a lot of procedural code, facts will probably be better.

The instance equivalent to retracting a fact is either to send it a delete message or call the unmake-instance function.

Jonas Rundberg

unread,
Nov 9, 2023, 5:48:02 PM11/9/23
to CLIPSESG
Thanks!
Reply all
Reply to author
Forward
0 new messages