Beispiel #1
0
 def substitute(self, subs, **kwargs):
     if can_sub(kwargs):
         for var, sub in subs.items():
             if can_sub(kwargs) and isinstance(var, Term) and self.name == var.name:
                 do_sub(kwargs)
                 if isvar(self) or self == var:
                     return sub
                 else:
                     return _coconut_tail_call(self.rename, sub.name)
     if can_sub(kwargs):
         return _coconut_tail_call(self.substitute_elements, subs, **kwargs)
     return self
Beispiel #2
0
 def substitute_elements(self, subs, **kwargs):
     if not can_sub(kwargs):
         return self
     _coconut_match_to_1 = subs
     _coconut_match_check_1 = False
     if _coconut.isinstance(_coconut_match_to_1, _coconut.abc.Mapping):
         _coconut_match_temp_0 = _coconut_match_to_1.get(self.proposition(), _coconut_sentinel)
         if _coconut_match_temp_0 is not _coconut_sentinel:
             sub = _coconut_match_temp_0
             _coconut_match_check_1 = True
     if _coconut_match_check_1:
         assert isinstance(sub, Atom), sub
         do_sub(kwargs)
         name = sub.name
     else:
         name = self.name
     if can_sub(kwargs):
         return (Pred)(name, *(map)(_coconut.operator.methodcaller("substitute", subs, **kwargs), self.args))
     else:
         return _coconut_tail_call(Pred, name, *self.args)
Beispiel #3
0
 def substitute(self, subs, **kwargs):
     if not can_sub(kwargs):
         return self
     _coconut_match_to_0 = subs
     _coconut_match_check_0 = False
     if _coconut.isinstance(_coconut_match_to_0, _coconut.abc.Mapping):
         _coconut_match_temp_0 = _coconut_match_to_0.get(self, _coconut_sentinel)
         if _coconut_match_temp_0 is not _coconut_sentinel:
             sub = _coconut_match_temp_0
             _coconut_match_check_0 = True
     if _coconut_match_check_0:
         do_sub(kwargs)
         if wff(sub):
             return sub
         elif sub is True:
             return top
         elif sub is False:
             return bot
         else:
             raise TypeError("cannot perform substitution " + str(self) + " => " + str(sub))
     else:
         return _coconut_tail_call(self.substitute_elements, subs, **kwargs)