premiseNegAtom semi-positive evaluation, i.e. looks up a and fails if it is present.
(a ast.Atom, store factstore.ReadOnlyFactStore, subst unionfind.UnionFind)
| 56 | |
| 57 | // premiseNegAtom semi-positive evaluation, i.e. looks up a and fails if it is present. |
| 58 | func premiseNegAtom(a ast.Atom, store factstore.ReadOnlyFactStore, subst unionfind.UnionFind) ([]unionfind.UnionFind, error) { |
| 59 | n, err := functional.EvalAtom(a, subst) |
| 60 | if err != nil { |
| 61 | return nil, err |
| 62 | } |
| 63 | |
| 64 | if n.Predicate.IsBuiltin() { |
| 65 | ok, _, err := builtin.Decide(n, &subst) |
| 66 | if err != nil { |
| 67 | return nil, err |
| 68 | } |
| 69 | if ok { |
| 70 | return nil, nil // negated: no solution |
| 71 | } |
| 72 | return []unionfind.UnionFind{subst}, nil |
| 73 | } |
| 74 | solutions := []unionfind.UnionFind{subst} |
| 75 | // If we find a single fact that unifies, then subst is not a solution. |
| 76 | err = store.GetFacts(n, func(fact ast.Atom) error { |
| 77 | if _, err := unionfind.UnifyTermsExtend(n.Args, fact.Args, subst); err == nil { |
| 78 | solutions = nil |
| 79 | return errBreak |
| 80 | } |
| 81 | return nil |
| 82 | }) |
| 83 | if err != nil && err != errBreak { |
| 84 | return nil, err |
| 85 | } |
| 86 | return solutions, nil |
| 87 | } |
| 88 | |
| 89 | func premiseEq(left, right ast.BaseTerm, subst unionfind.UnionFind) ([]unionfind.UnionFind, error) { |
| 90 | left, right, err := functional.EvalBaseTermPair(left, right, subst) |
no test coverage detected