0% found this document useful (0 votes)
35 views

Why Modify

Why Modify

Uploaded by

carlcols
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
35 views

Why Modify

Why Modify

Uploaded by

carlcols
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Why Modify?

To Illustrate the purpose of modify lets look a small example


In this example I have a simple model
A single fact in my model called Car
My Car fact has two fields: make (a Text field) and speed (an int)

Copyright 2011 Red Hat, Inc. All Rights Reserved.

Why Modify?
I now add one rule to my system called accelerate car
Notice that I have the no-loop attribute turned off
If I were to run a test scenario where I place one Car object into
working memory, what would you expect to happen?

Copyright 2011 Red Hat, Inc. All Rights Reserved.

Why Modify?
Since the no-loop attribute is off, you might expect this to result in an
infinite loop. However, as you can see below, the rule is only activated
one time.
Why? The rule engine is never informed that anything has changed in
working memory.

Copyright 2011 Red Hat, Inc. All Rights Reserved.

Why Modify?
If I change the rule by adding update or modify, then I also need to set
the no-loop attribute to true. Why?
Every update or modify command will inform the rule engine to do a reevaluation of the fact since something has changed on fact.
So in this case, no-loop must be set to prevent an infinite loop.

Copyright 2011 Red Hat, Inc. All Rights Reserved.

Why Modify?
To be clear, no-loop is not the only way to prevent an infinite loop. I
would suggest that the use of no-loop should be a last resort.
The following rule is one example of how to stop the infinite loop without
using the no-loop attribute.

Copyright 2011 Red Hat, Inc. All Rights Reserved.

You might also like