(a ast.Atom, lookupFn func(p ast.Atom, cb func(ast.Atom) error) error, subst unionfind.UnionFind)
| 23 | ) |
| 24 | |
| 25 | func premiseAtom(a ast.Atom, lookupFn func(p ast.Atom, cb func(ast.Atom) error) error, subst unionfind.UnionFind) ([]unionfind.UnionFind, error) { |
| 26 | p, err := functional.EvalAtom(a, subst) |
| 27 | if err != nil { |
| 28 | return nil, err |
| 29 | } |
| 30 | var solutions []unionfind.UnionFind |
| 31 | if p.Predicate.IsBuiltin() { |
| 32 | ok, nsubsts, err := builtin.Decide(p, &subst) |
| 33 | if err != nil { |
| 34 | return nil, err |
| 35 | } |
| 36 | if !ok { |
| 37 | return nil, nil // no solution |
| 38 | } |
| 39 | for _, nsubst := range nsubsts { |
| 40 | solutions = append(solutions, *nsubst) |
| 41 | } |
| 42 | return solutions, nil |
| 43 | } |
| 44 | // Not a built-in predicate. Call lookupFn. |
| 45 | lookupFn(p, func(fact ast.Atom) error { |
| 46 | // TODO: This could be made a lot more efficient by using a persistent |
| 47 | // data structure for composing the unionfind substitutions. |
| 48 | if newSubst, err := unionfind.UnifyTermsExtend(p.Args, fact.Args, subst); err == nil { |
| 49 | solutions = append(solutions, newSubst) |
| 50 | } |
| 51 | return nil |
| 52 | }) |
| 53 | return solutions, nil |
| 54 | |
| 55 | } |
| 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) { |
no test coverage detected