Decide evaluates an atom of a built-in predicate. The atom must no longer contain any apply-expressions or variables.
(atom ast.Atom, subst *unionfind.UnionFind)
| 214 | // Decide evaluates an atom of a built-in predicate. The atom must no longer contain any |
| 215 | // apply-expressions or variables. |
| 216 | func Decide(atom ast.Atom, subst *unionfind.UnionFind) (bool, []*unionfind.UnionFind, error) { |
| 217 | // Check for temporal predicates first |
| 218 | if IsTemporalPredicate(atom.Predicate) { |
| 219 | return DecideTemporalPredicate(atom, subst) |
| 220 | } |
| 221 | |
| 222 | switch atom.Predicate.Symbol { |
| 223 | case symbols.StartsWith.Symbol: |
| 224 | fallthrough |
| 225 | case symbols.EndsWith.Symbol: |
| 226 | fallthrough |
| 227 | case symbols.Contains.Symbol: |
| 228 | fallthrough |
| 229 | case symbols.MatchPrefix.Symbol: |
| 230 | fallthrough |
| 231 | case symbols.MatchPair.Symbol: |
| 232 | fallthrough |
| 233 | case symbols.MatchCons.Symbol: |
| 234 | fallthrough |
| 235 | case symbols.MatchEntry.Symbol: |
| 236 | fallthrough |
| 237 | case symbols.MatchField.Symbol: |
| 238 | fallthrough |
| 239 | case symbols.MatchNil.Symbol: |
| 240 | ok, nsubst, err := match(atom, subst) |
| 241 | if err != nil { |
| 242 | return false, nil, err |
| 243 | } |
| 244 | if !ok { |
| 245 | return false, nil, nil |
| 246 | } |
| 247 | return ok, []*unionfind.UnionFind{nsubst}, nil |
| 248 | } |
| 249 | switch atom.Predicate.Symbol { |
| 250 | case symbols.Filter.Symbol: |
| 251 | if len(atom.Args) != 1 { |
| 252 | return false, nil, fmt.Errorf("wrong number of arguments for built-in predicate 'filter': %v", atom.Args) |
| 253 | } |
| 254 | evaluatedArg, err := functional.EvalExpr(atom.Args[0], subst) |
| 255 | if err != nil { |
| 256 | return false, nil, err |
| 257 | } |
| 258 | if evaluatedArg == ast.TrueConstant { |
| 259 | return true, []*unionfind.UnionFind{subst}, nil |
| 260 | } |
| 261 | return false, nil, nil |
| 262 | |
| 263 | case symbols.Lt.Symbol: |
| 264 | if len(atom.Args) != 2 { |
| 265 | return false, nil, fmt.Errorf("wrong number of arguments for built-in predicate '<': %v", atom.Args) |
| 266 | } |
| 267 | nums, err := getNumberValues(atom.Args) |
| 268 | if err != nil { |
| 269 | return false, nil, err |
| 270 | } |
| 271 | return nums[0] < nums[1], []*unionfind.UnionFind{subst}, nil |
| 272 | case symbols.Le.Symbol: |
| 273 | if len(atom.Args) != 2 { |