def impl_functor(engine, t, functor, arity): if helper.is_atomic(t): functor.unify(t, engine.heap) arity.unify(term.Number(0), engine.heap) elif isinstance(t, term.Term): functor.unify(term.Atom(t.name), engine.heap) arity.unify(term.Number(len(t.args)), engine.heap) elif isinstance(t, term.Var): if isinstance(functor, term.Var): error.throw_instantiation_error() a = helper.unwrap_int(arity) if a < 0: error.throw_domain_error("not_less_than_zero", arity) else: functor = helper.ensure_atomic(functor) if a == 0: t.unify(helper.ensure_atomic(functor), engine.heap) else: name = helper.unwrap_atom(functor) t.unify(term.Term(name, [term.Var() for i in range(a)]), engine.heap)
def impl_functor(engine, t, functor, arity): if helper.is_atomic(t): functor.unify(t, engine.heap) arity.unify(term.Number(0), engine.heap) elif isinstance(t, term.Term): functor.unify(term.Atom(t.name), engine.heap) arity.unify(term.Number(len(t.args)), engine.heap) elif isinstance(t, term.Var): if isinstance(functor, term.Var): error.throw_instantiation_error() a = helper.unwrap_int(arity) if a < 0: error.throw_domain_error("not_less_than_zero", arity) else: functor = helper.ensure_atomic(functor) if a == 0: t.unify(helper.ensure_atomic(functor), engine.heap) else: name = helper.unwrap_atom(functor) t.unify( term.Term(name, [term.Var() for i in range(a)]), engine.heap)
def impl_atomic(engine, var): if helper.is_atomic(var): return raise error.UnificationFailed()