MCPcopy
hub / github.com/google/mangle / premiseAtom

Function premiseAtom

engine/premise.go:25–55  ·  view source on GitHub ↗
(a ast.Atom, lookupFn func(p ast.Atom, cb func(ast.Atom) error) error, subst unionfind.UnionFind)

Source from the content-addressed store, hash-verified

23)
24
25func 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.
58func premiseNegAtom(a ast.Atom, store factstore.ReadOnlyFactStore, subst unionfind.UnionFind) ([]unionfind.UnionFind, error) {

Callers 2

oneStepEvalPremiseMethod · 0.85
EvalPremiseMethod · 0.85

Calls 4

EvalAtomFunction · 0.92
DecideFunction · 0.92
UnifyTermsExtendFunction · 0.92
IsBuiltinMethod · 0.80

Tested by

no test coverage detected