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

mistake in fact_type_fn_perf doc #35

Closed
lambda-ai opened this issue Dec 22, 2020 · 0 comments · Fixed by #36
Closed

mistake in fact_type_fn_perf doc #35

lambda-ai opened this issue Dec 22, 2020 · 0 comments · Fixed by #36

Comments

@lambda-ai
Copy link

From the google group (https://groups.google.com/g/clara-rules/c/F5ZC-uiIfa0/m/KPPUWbrwBAAJ):

This is a bit of an oddity that I believe i have seen before. The issue seems to be with how clara resolves the fact type of the rule. Looking at the compiler code when generating the alpha nodes, if the fact-type is a symbol then it will be converted to a class otherwise it will remain as what ever was provided. This is to facilitate the default usage, ie. type as the default fact-type-fn.

In the example you provided, this would mean that the fact type of rule1 would match on [`IdHolder "A"] and not [IdHolder "A"], the former being a vector composed of a symbol/string combo and the latter being a class/string combo.

Im a bit torn here on what should be expected of clara in this situation, I feel its not very transparent that in one case the symbol would be replaced by a class but on the other hand it might be dangerous for clara to try and traverse the fact-type and replace symbols.

All of that being said, to answer the question, to get the example to function as expected:

(fn [fact]
  (cond
    (instance? IdHolder fact) [IdHolder (:id fact)]
    :else (type fact)))

would simply need updated to:


(fn [fact]
  (cond
    (instance? IdHolder fact) [`IdHolder (:id fact)]
    :else (type fact)))

Hope this helps,
Ethan

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

Successfully merging a pull request may close this issue.

1 participant