David Schneider committed 8d60bd5

add helper method is_term and use it

  • Participants
  • Parent commits 62238d0
  • Branches continuation-based

Comments (0)

Files changed (4)

File prolog/builtin/

 def impl_or(engine, heap, call1, call2, scont, fcont):
     # sucks a bit to have to special-case A -> B ; C here :-(
     if call1.signature()== "->/2":
-        assert isinstance(call1, term.Term)
+        assert helper.is_term(call1)
         scont = fcont = continuation.CutDelimiter(engine, scont, fcont)
         fcont = OrContinuation(engine, scont, heap, fcont, call2)
         newscont, fcont, heap = impl_if(

File prolog/builtin/

 @expose_builtin("retract", unwrap_spec=["callable"])
 def impl_retract(engine, heap, pattern):
     from prolog.builtin import builtins
-    if isinstance(pattern, term.Term) and ":-":
+    if helper.is_term(pattern) and ":-":
         head = helper.ensure_callable(pattern.argument_at(0))
         body = helper.ensure_callable(pattern.argument_at(1))

File prolog/interpreter/

 import py
 from pypy.rlib import jit
 from prolog.interpreter import error
+from prolog.interpreter import helper
 from prolog.interpreter.term import Term, Atom, Var, Callable
 from prolog.interpreter.function import Function, Rule
     def add_rule(self, rule, end=True):
         from prolog import builtin
-        if isinstance(rule, Term):
+        if helper.is_term(rule):
             if ":-":
                 rule = Rule(rule.argument_at(0), rule.argument_at(1))

File prolog/interpreter/

     return (isinstance(obj, term.Atom) or isinstance(obj, term.Float) or 
             isinstance(obj, term.Number))
+def is_term(obj):
+    return (not isinstance(obj, term.Atom) and isinstance(obj, term.Callable)
+            and obj.argument_count() > 0)
 def convert_to_str(obj):
     if isinstance(obj, term.Var):