datascript
datascript copied to clipboard
Infinite loop in rule solver
The following code will result in the query hanging
var ds = require("datascript")
var db = ds.db_with(ds.empty_db(), [
{
"left": "aaron",
"right": "barbara"
},
{
"left": "aaron",
"right": "chris"
}
])
var rules = `[
[
(friends ?a ?b)
[?i "left" ?a]
[?i "right" ?b]
]
[
(friends ?a ?b)
(friends ?a ?c)
(friends ?c ?b)
]
]`
console.log(ds.q(`[:find ?a ?b :in $ % :where (friends ?a ?b)]`, db, rules))
It's fairly similar to the transitive closure example in the README, but it uses an additional call to the rule in the non-base case. My understanding is that datalog queries should always terminate, so apologies if this isn't actually a bug.
Well this should work. Thanks for reporting, I’ll take a look later