How to inspect why a rule has fired

44 views
Skip to first unread message

Jose Antonio Escribano Ayllon

unread,
Apr 9, 2024, 6:36:40 AMApr 9
to CLIPSESG
Hi,

I have built a debugger to see the state of the facts databaase and to keep track of the rules that fired.

I made use of AddBeforeRuleFiresFunction and AddAfterRuleFiresFunction, and that works pretty nice, but I was wondering if there is any way to inspect why certain rule doesn't fire. 

I guess I can check that on the agenda, but I haven't found any example about that.

Any help?

Cheers,
Jose

Ryan Johnston

unread,
Apr 9, 2024, 7:56:27 AMApr 9
to clip...@googlegroups.com
You may want to `(watch activations)`. `(watch all)` is also helpful. Both will enable debug output at various parts in your CLIPS program. activations will pop up when a rule is "activated" (it is placed on the agenda and will fire when the engine is run) or "deactivated" (a rule's pattern no longer matches a given set of facts, and thus must be removed from the agenda). Check out section 13.2 of the Basic Programming Guide for some more info on stuff you can watch.

What I'll usually do is set up a "known state" by doing `(save my_facts.clp)` so I can quickly `(load my_facts)` and then `(run)` to re-create the issue with different debugging streams watched.

--
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To post to this group, send email to CLIP...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/CLIPSESG?hl=en
 
--> IF YOU NO LONGER WANT TO RECEIVE EMAIL <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Click on "Edit my membership" link.
Select the "No Email" radio button.
Click the "Save these settings" button.

--> IF YOU WANT TO UNSUBSCRIBE <--
Visit this group at http://groups.google.com/group/CLIPSESG?hl=en
Sign in
Click on "Edit my membership" link.
Click the "Unsubscribe" button.
Note: This appears to be the most reliable way to unsubscribe
 
Alternately, send email to CLIPSESG-u...@googlegroups.com. You will receive an email which you must respond to as well to unsubscribe. Clicking the link mentioned in the unsubscribe reply does not appear to work reliably.
---
You received this message because you are subscribed to the Google Groups "CLIPSESG" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clipsesg+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/clipsesg/253d4160-0a48-49f2-ad98-b380fbb518e6n%40googlegroups.com.

Jose Antonio

unread,
Apr 9, 2024, 12:45:50 PMApr 9
to CLIPSESG
Hi Ryan.

Thanks! That is really useful.
And I what if I want to check why a rule does NOT fire? Is there any way to gather that info by using the watch command?

Cheers,
Jose

CLIPS Support

unread,
Apr 9, 2024, 12:49:08 PMApr 9
to CLIPSESG
Use the matches command. That will show you which patterns have been matched in a rule.

         CLIPS (6.4.1 4/8/23)
CLIPS>
(defrule example
   (a)
   (b)
   (c)
   (d)
   =>)
CLIPS> (assert (a) (b) (d))
<Fact-3>
CLIPS> (agenda)
CLIPS> (matches example)
Matches for Pattern 1
f-1
Matches for Pattern 2
f-2
Matches for Pattern 3
 None
Matches for Pattern 4
f-3
Partial matches for CEs 1 - 2
f-1,f-2
Partial matches for CEs 1 - 3
 None
Partial matches for CEs 1 - 4
 None
Activations
 None
(3 1 0)
CLIPS> 

Jose Antonio Escribano Ayllon

unread,
Apr 10, 2024, 4:35:29 AMApr 10
to CLIPSESG
Thanks! 

I managed to have it pretty much working.
I was expecting to be able to gather that pretty print debugging in my C++ code, but functions like ListAlphaMatches are writing the info directly into the STDOUT logical name, I suppose there is no way to redirect that to my own logical name right?

I check the documentation but I haven't seen a way to do that.

Cheers,
Jose

CLIPS Support

unread,
Apr 10, 2024, 5:23:12 PMApr 10
to CLIPSESG
You can create an I/O router to capture output to specific logical names. There are examples in section 9.7 of the Advanced Programming Guide. The CLIPS .NET wrapper makes use of this facility to capture output from STDERR to create exceptions. You could do something similar in your C++ code.

Jose Antonio Escribano Ayllon

unread,
Apr 11, 2024, 9:24:19 AMApr 11
to CLIPSESG
Thanks, that works perfectly.

Cheers,
Jose

Reply all
Reply to author
Forward
0 new messages