posh
posh copied to clipboard
Recursive rules fail in new version of posh
This worked in posh 3.5
(def prereqs-rule
'[[(prereqs ?e ?p)
[?e :node/prereqs ?p]]
[(prereqs ?e ?p)
[?e :node/prereqs ?p1]
(prereqs ?p1 ?p)]])
(posh/q conn '[:find [?p ...]
:in $ % ?item
:where (prereqs ?item ?p)]
prereqs-rule
1)
In posh 5, the equivalent
(posh/q '[:find [?p ...]
:in $ % ?item
:where (prereqs ?item ?p)]
conn
prereqs-rule
1)
This produces an error of
#error {:message "Cannot parse rule-expr arguments, expected [ (variable | constant | '_')+ ]", :data {:error :parser/where, :form (prereqs $ ?p ?e ?var3284835)}}
Somehow I missed this message;
I think back in 3.5, either it was just always rerunning things when rules are involved, or it was actually doing the wrong thing, or it was doing something stupider than what it's doing now (since then, the pattern engine has been rewritten). The specific error here has to do with the query parsing, which is maybe an easy fix (in fact, based on the error message, you might want to try just switching :where (prereqs ?item ?p)
to :where [prereqs ?item ?p]
, which should be valid DS). However, the underlying probably will persist I believe (you're welcome to test out).
Again, fixing rules may be more of a mess than its worth, given other things on the horizon. You're welcome to try and prove me wrong though.