Commits

David Schneider  committed f7970ea

Add factory method to callable to create terms an Atoms

  • Participants
  • Parent commits 23c6757
  • Branches continuation-based

Comments (0)

Files changed (2)

File prolog/interpreter/term.py

                 self.argument_at(i).unify(other.argument_at(i), heap, occurs_check)
         else:
             raise UnificationFailed
-
+    
+    @staticmethod
+    def build(term_name, args=None, signature=None):
+        if args is None:
+            args = []
+        if len(args) == 0:
+            return Atom.newatom(term_name)
+        else:
+            return Term(term_name, args, signature)
+        
 class Atom(Callable):
     TYPE_STANDARD_ORDER = 1
     # __slots__ = ('_name', '_signature')

File prolog/interpreter/test/test_callable_interface.py

     assert term.name() == 't'
     
 def test_term_signature():
-    assert term.signature() == 't/5'
+    assert term.signature() == 't/5'
+    
+def test_callable_factory_for_atom():
+    r = Callable.build('foo')
+    assert isinstance(r, Atom)
+    assert r.signature() == 'foo/0'
+
+def test_callable_factory_for_term_with_empty_args():
+    r = Callable.build('bar', [])
+    assert isinstance(r, Atom)
+    assert r.signature() == 'bar/0'
+
+def test_callable_factory_for_term():
+    r = Callable.build('foo', [1, 2])
+    assert isinstance(r, Term)
+    assert r.signature() == 'foo/2'