Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

:exists conditions perform downstream work when their state didn't change #298

Closed
WilliamParker opened this issue May 22, 2017 · 2 comments

Comments

@WilliamParker
Copy link
Collaborator

We added support for :exists conditions that only fire once per binding group with #130. Since they use a count accumulator behind the scenes, Clara will consider a change to have taken place each time a match is added or removed, even if it doesn't change whether a match exists. This implementation can be found in extract-exists. For example, suppose we have a condition like

[:exists [Cold]]

and 2 Cold facts in the session. We shouldn't perform any downstream work in the rules network when we retract or add 1 Cold fact since we'd have 1 or 3 Cold facts afterward. That is, we have a Cold fact before and a Cold fact after in these cases, so the answer to the question "Does a Cold fact exist in the session" did not change. However, we will current retract downstream work based on a count of 2 and then perform that work again based on a count of 3, even though the count is only used by a :test condition added by extract-exists that determines whether the count is positive.

We can improve this by adding a :convert-return-fn to the accumulator in this case that returns true if the count is greater than 0 and nil if is 0. Due to the enhancements in #182 if the final result of the accumulator does not change then work will not be performed downstream in the rules network.

@WilliamParker
Copy link
Collaborator Author

PR at #411

@WilliamParker
Copy link
Collaborator Author

Resolved by #411 , closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant