This is very inefficient because it generates the same facts over and over again.
()
| 89 | |
| 90 | // This is very inefficient because it generates the same facts over and over again. |
| 91 | func (e naiveEngine) eval() { |
| 92 | for { |
| 93 | factadded := false |
| 94 | for _, clause := range e.programInfo.Rules { |
| 95 | if clause.Transform != nil { |
| 96 | continue |
| 97 | } |
| 98 | for _, fact := range e.oneStepEvalClause(clause) { |
| 99 | if e.store.Add(fact) { |
| 100 | factadded = true |
| 101 | } |
| 102 | } |
| 103 | } |
| 104 | if !factadded { |
| 105 | break |
| 106 | } |
| 107 | } |
| 108 | for _, clause := range e.programInfo.Rules { |
| 109 | if clause.Transform == nil { |
| 110 | continue |
| 111 | } |
| 112 | internalPremise := clause.Premises[0].(ast.Atom) |
| 113 | var substs []ast.ConstSubstList |
| 114 | e.store.GetFacts(internalPremise, func(fact ast.Atom) error { |
| 115 | var subst ast.ConstSubstList |
| 116 | for i, baseTerm := range internalPremise.Args { |
| 117 | v, _ := baseTerm.(ast.Variable) |
| 118 | subst = subst.Extend(v, fact.Args[i].(ast.Constant)) |
| 119 | } |
| 120 | substs = append(substs, subst) |
| 121 | return nil |
| 122 | }) |
| 123 | EvalTransform(clause.Head, *clause.Transform, substs, e.store.Add) |
| 124 | } |
| 125 | } |
| 126 | |
| 127 | // Evaluates clause, by scanning known facts for each premise and producing |
| 128 | // a solution (conjunctive query, similar to a join). |
no test coverage detected