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

Method EvalPremise

engine/topdown.go:142–177  ·  view source on GitHub ↗

EvalPremise evaluates a single premise top-down. This is similar to PROLOG style SLD resolution: even though we have negated atoms, they are treated them as lookups (stratified semantics).

(premise ast.Term, subst unionfind.UnionFind)

Source from the content-addressed store, hash-verified

140// This is similar to PROLOG style SLD resolution: even though we
141// have negated atoms, they are treated them as lookups (stratified semantics).
142func (q QueryContext) EvalPremise(premise ast.Term, subst unionfind.UnionFind) ([]unionfind.UnionFind, error) {
143 var solutions []unionfind.UnionFind
144 switch p := premise.(type) {
145 case ast.Atom:
146 p, err := functional.EvalAtom(p, subst)
147 if err != nil {
148 return nil, err
149 }
150 decl := q.PredToDecl[p.Predicate]
151 if decl != nil && decl.DeferredPredicate() {
152 err := q.EvalQuery(p, decl.Modes()[0], subst, func(fact ast.Atom) error {
153 newsubst, err := unionfind.UnifyTermsExtend(p.Args, fact.Args, subst)
154 if err != nil {
155 return err
156 }
157 solutions = append(solutions, newsubst)
158 return nil
159 })
160 if err != nil {
161 return nil, err
162 }
163 return solutions, nil
164 }
165 return premiseAtom(p, q.Store.GetFacts, subst)
166
167 case ast.NegAtom:
168 return premiseNegAtom(p.Atom, q.Store, subst)
169
170 case ast.Eq:
171 return premiseEq(p.Left, p.Right, subst)
172
173 case ast.Ineq:
174 return premiseIneq(p.Left, p.Right, subst)
175 }
176 return nil, nil
177}

Callers 2

EvalQueryMethod · 0.95
oneStepEvalPremiseMethod · 0.80

Calls 9

EvalQueryMethod · 0.95
EvalAtomFunction · 0.92
UnifyTermsExtendFunction · 0.92
premiseAtomFunction · 0.85
premiseNegAtomFunction · 0.85
premiseEqFunction · 0.85
premiseIneqFunction · 0.85
DeferredPredicateMethod · 0.80
ModesMethod · 0.80

Tested by

no test coverage detected