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)
| 140 | // This is similar to PROLOG style SLD resolution: even though we |
| 141 | // have negated atoms, they are treated them as lookups (stratified semantics). |
| 142 | func (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 | } |
no test coverage detected