David Schneider avatar David Schneider committed 23c6757

Refactor name and signarture fields of callable into methods, implemented by each subclass

Comments (0)

Files changed (22)

prolog/builtin/control.py

                 handles_continuation=True)
 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":
+    if call1.signature()== "->/2":
         assert isinstance(call1, term.Term)
         scont = fcont = continuation.CutDelimiter(engine, scont, fcont)
         fcont = OrContinuation(engine, scont, heap, fcont, call2)

prolog/builtin/database.py

 @expose_builtin("retract", unwrap_spec=["callable"])
 def impl_retract(engine, heap, pattern):
     from prolog.builtin import builtins
-    if isinstance(pattern, term.Term) and pattern.name == ":-":
+    if isinstance(pattern, term.Term) and pattern.name()== ":-":
         head = helper.ensure_callable(pattern.argument_at(0))
         body = helper.ensure_callable(pattern.argument_at(1))
     else:
         head = pattern
         body = None
-    if head.signature in builtins:
+    if head.signature()in builtins:
         assert isinstance(head, term.Callable)
         error.throw_permission_error("modify", "static_procedure", 
                                      head.get_prolog_signature())
-    function = engine.signature2function.get(head.signature, None)
+    function = engine.signature2function.get(head.signature() None)
     if function is None:
         raise error.UnificationFailed
     #import pdb; pdb.set_trace()
         else:
             if function.rulechain is rulechain:
                 if rulechain.next is None:
-                    del engine.signature2function[head.signature]
+                    del engine.signature2function[head.signature()
                 else:
                     function.rulechain = rulechain.next
             else:

prolog/builtin/formatting.py

             if (not isinstance(option, Term) or len(option.argument_count()) != 1):
                 error.throw_domain_error('write_option', option)
             arg = option.argument_at(0)
-            if option.name == "max_depth":
+            if option.name()== "max_depth":
                 try:
                     max_depth = helper.unwrap_int(arg)
                 except error.CatchableError:
                     error.throw_domain_error('write_option', option)
             elif (not isinstance(arg, Atom) or
-                (arg.name != "true" and arg.name != "false")):
+                (arg.name()!= "true" and arg.name()!= "false")):
                 error.throw_domain_error('write_option', option)
                 assert 0, "unreachable"
-            elif option.name == "quoted":
-                quoted = arg.name == "true"
-            elif option.name == "ignore_ops":
-                ignore_ops = arg.name == "true"
+            elif option.name()== "quoted":
+                quoted = arg.name()== "true"
+            elif option.name()== "ignore_ops":
+                ignore_ops = arg.name()== "true"
         return TermFormatter(engine, quoted, max_depth, ignore_ops)
     from_option_list = staticmethod(from_option_list)
 
         if self.max_depth > 0 and self.curr_depth > self.max_depth:
             return "..."
         if isinstance(term, Atom):
-            return self.format_atom(term.name)
+            return self.format_atom(term.name())
         elif isinstance(term, Number):
             return self.format_number(term)
         elif isinstance(term, Float):
         return "_G%s" % (num, )
 
     def format_term_normally(self, term):
-        return "%s(%s)" % (self.format_atom(term.name),
+        return "%s(%s)" % (self.format_atom(term.name()),
                            ", ".join([self.format(a) for a in term.arguments()]))
 
     def format_term(self, term):
     def format_with_ops(self, term):
         if not isinstance(term, Term):
             return (0, self.format(term))
-        if term.signature == "./2":
+        if term.signature()== "./2":
             result = ["["]
-            while isinstance(term, Term) and term.signature == "./2":
+            while isinstance(term, Term) and term.signature()== "./2":
                 first = term.argument_at(0)
                 second = term.argument_at(1)
                 result.append(self.format(first))
                 result.append(", ")
                 term = second
-            if isinstance(term, Atom) and term.name == "[]":
+            if isinstance(term, Atom) and term.name()== "[]":
                 result[-1] = "]"
             else:
                 result[-1] = "|"
                 result.append(self.format(term))
                 result.append("]")
             return (0, "".join(result))
-        if (term.argument_count(), term.name) not in self.op_mapping:
+        if (term.argument_count(), term.name()) not in self.op_mapping:
             return (0, self.format_term_normally(term))
-        form, prec = self.op_mapping[(term.argument_count(), term.name)]
+        form, prec = self.op_mapping[(term.argument_count(), term.name())]
         result = []
         assert 0 <= term.argument_count() <= 2
         curr_index = 0
         for c in form:
             if c == "f":
-                result.append(self.format_atom(term.name))
+                result.append(self.format_atom(term.name()))
             else:
                 childprec, child = self.format_with_ops(term.argument_at(curr_index))
                 parentheses = (c == "x" and childprec >= prec or

prolog/builtin/register.py

     _immutable_ = True
     def __init__(self, function, name, numargs, signature):
         self.function = function
-        self.name = name
+        self.name= name
         self.numargs = numargs
-        self.signature = signature
+        self.signature= signature
 
     def call(self, engine, query, scont, fcont, heap):
         return self.function(engine, query, scont, fcont, heap)

prolog/builtin/source.py

     import os
     if isinstance(var, term.Atom):
         try:
-            fd = os.open(var.name, os.O_RDONLY, 0777)
+            fd = os.open(var.name() os.O_RDONLY, 0777)
         except OSError, e:
             error.throw_existence_error("source_sink", var)
             assert 0, "unreachable" # make the flow space happy

prolog/builtin/termconstruction.py

         functor.unify(t, heap)
         arity.unify(term.Number(0), heap)
     elif isinstance(t, term.Term):
-        functor.unify(term.Atom(t.name), heap)
+        functor.unify(term.Atom(t.name()), heap)
         arity.unify(term.Number(t.argument_count()), heap)
     elif isinstance(t, term.Var):
         if isinstance(functor, term.Var):
 def impl_univ(engine, heap, first, second):
     if not isinstance(first, term.Var):
         if isinstance(first, term.Term):
-            l = [term.Atom(first.name)] + first.arguments()
+            l = [term.Atom(first.name())] + first.arguments()
         else:
             l = [first]
         u1 = helper.wrap_list(l)
             head = l[0]
             if not isinstance(head, term.Atom):
                 error.throw_type_error("atom", head)
-            term.Term(head.name, l[1:]).unify(first, heap)
+            term.Term(head.name(), l[1:]).unify(first, heap)
 
 @expose_builtin("copy_term", unwrap_spec=["obj", "obj"])
 def impl_copy_term(engine, heap, interm, outterm):

prolog/interpreter/continuation.py

 
 def get_printable_location(rule):
     if rule:
-        s = rule.signature
+        s = rule.signature()    
     else:
         s = "No rule"
     return s
     def add_rule(self, rule, end=True):
         from prolog import builtin
         if isinstance(rule, Term):
-            if rule.name == ":-":
+            if rule.name()== ":-":
                 rule = Rule(rule.argument_at(0), rule.argument_at(1))
             else:
                 rule = Rule(rule, None)
         else:
             error.throw_type_error("callable", rule)
             assert 0, "unreachable" # make annotator happy
-        signature = rule.signature
+        signature = rule.signature        
         if signature in builtin.builtins:
             error.throw_permission_error(
                 "modify", "static_procedure", rule.head.get_prolog_signature())
         from prolog.interpreter.parsing import TermBuilder
         builder = TermBuilder()
         term = builder.build_query(tree)
-        if isinstance(term, Term) and term.signature == ":-/1":
+        if isinstance(term, Term) and term.signature()== ":-/1":
             self.run(term.argument_at(0))
         else:
             self.add_rule(term)
     def call(self, query, scont, fcont, heap):
         if not isinstance(query, Callable):
             raise error.throw_type_error('callable', query)
-        signature = query.signature
+        signature = query.signature()        
         builtin = self.get_builtin(signature)
         if builtin is not None:
             return BuiltinContinuation(self, scont, builtin, query), fcont, heap
     def __init__(self, engine, nextcont, query, rulechain):
         ChoiceContinuation.__init__(self, engine, nextcont)
         self.query = query
-        signature = query.signature
+        signature = query.signature()        
         self.rulechain = rulechain
 
     def activate(self, fcont, heap):

prolog/interpreter/eclipseprologparser.py

         token = None
         for child in node.children:
             if isinstance(child, Symbol):
-                name = self.general_symbol_visit(child).name
-                token = self.make_token(child)
+                name = self.general_symbol_visit(child).name()                token = self.make_token(child)
             else:
                 children.append(child)
         children = [self.visit(child) for child in children]
             return result
 
     def visit_complexterm(self, node):
-        name = self.general_symbol_visit(node.children[0]).name
-        children = self.build_list(node.children[2])
+        name = self.general_symbol_visit(node.children[0]).name()        children = self.build_list(node.children[2])
         result = Term()
         result.setup(self.make_token(node.children[1]), children, name)
         return result
         pass
     def setup(self, token, name):
         Node.setup(self, token)
-        self.name = name
+        self.name()= name
 
 class Number(Node):
     def __init__(self):
         pass
     def setup(self, token, children, name):
         Node.setup(self, token, children)
-        self.name = name
+        self.name()= name
 
 
 class Lines(object):
     from prolog.interpreter.parsing import TermBuilder
     builder = ASTTermBuilder()
     term = builder.build_query(tree)
-    if (isinstance(term, Term) and term.name == ":-" and
+    if (isinstance(term, Term) and term.name()== ":-" and
             len(term.children) == 1):
         child = term.get_child(0)
-        if isinstance(child, Term) and child.name == "op":
+        if isinstance(child, Term) and child.name()== "op":
             if len(child.children) != 3:
                 raise ParseError(child.token.startpos, "expecting three arguments")
             precedence = child.children[0]
                 raise ParseError(precedence.token.startpos, "second argument to op should be atom")
             if not isinstance(name, Atom):
                 raise ParseError(precedence.token.startpos, "third argument to op should be atom")
-            parser = impl_op(lines.operations, precedence.value, form.name, name.name)
+            parser = impl_op(lines.operations, precedence.value, form.name() name.name()
             lines.parser = parser
 
     lines.terms.append(term)

prolog/interpreter/function.py

         else:
             self.body = None
         self.size_env = len(memo)
-        self.signature = head.signature
+        self.signature = head.signature()        
         self._does_contain_cut()
 
         self.next = next
         while stack:
             current = stack.pop()
             if isinstance(current, Atom):
-                if current.name == "!":
+                if current.name()== "!":
                     self.contains_cut = True
                     return
             elif isinstance(current, Term):

prolog/interpreter/helper.py

     result = []
     curr = prolog_list
     while isinstance(curr, term.Term):
-        if not curr.name == ".":
+        if not curr.name()== ".":
             error.throw_type_error("list", prolog_list)
         result.append(curr.argument_at(0))
         curr = curr.argument_at(1)
-    if isinstance(curr, term.Atom) and curr.name == "[]":
+    if isinstance(curr, term.Atom) and curr.name()== "[]":
         return result
     error.throw_type_error("list", prolog_list)
 
 
 def unwrap_atom(obj):
     if isinstance(obj, term.Atom):
-        return obj.name
+        return obj.name()    
     error.throw_type_error('atom', obj)
 
 def unwrap_predicate_indicator(predicate):
     if not isinstance(predicate, term.Term):
         error.throw_type_error("predicate_indicator", predicate)
         assert 0, "unreachable"
-    if not predicate.name == "/" or predicate.argument_count() != 2:
+    if not predicate.name()== "/" or predicate.argument_count() != 2:
         error.throw_type_error("predicate_indicator", predicate)
     name = unwrap_atom(predicate.argument_at(0))
     arity = unwrap_int(predicate.argument_at(1))
     if isinstance(obj, term.Var):
         error.throw_instantiation_error()
     if isinstance(obj, term.Atom):
-        return obj.name
+        return obj.name()    
     elif isinstance(obj, term.Number):
         return str(obj.num)
     elif isinstance(obj, term.Float):

prolog/interpreter/interactive.py

             self.write("no\n")
         except error.CatchableError, e:
             self.write("ERROR: ")
-            if e.term.argument_at(0).name == "instantiation_error":
+            if e.term.argument_at(0).name()== "instantiation_error":
                 print e.term
                 self.write("arguments not sufficiently instantiated\n")
-            elif e.term.argument_at(0).name == "existence_error":
+            elif e.term.argument_at(0).name()== "existence_error":
                 print e.term
                 self.write("Undefined %s: %s\n" % (e.term.argument_at(0).argument_at(0),
                                                    e.term.argument_at(0).argument_at(1)))

prolog/interpreter/parsing.py

         if input.name == "ATOM":
             return symbol == "ATOM" or symbol == input.source
         return symbol == input.name
-
 class PrologPackratParser(PackratParser):
     def __init__(self, rules, startsymbol):
         PackratParser.__init__(self, rules, startsymbol, PrologParseTable,
     line = []
     for tok in tokens:
         line.append(tok)
-        if tok.name == ".":
+        if tok.name== ".":
             lines.append(line)
             line = []
     if parser is None:
         name = ""
         for child in node.children:
             if isinstance(child, Symbol):
-                name = self.general_symbol_visit(child).name
+                name = self.general_symbol_visit(child).name()            
             else:
                 children.append(child)
         children = [self.visit(child) for child in children]
 
     def visit_complexterm(self, node):
         from prolog.interpreter.term import Term
-        name = self.general_symbol_visit(node.children[0]).name
+        name = self.general_symbol_visit(node.children[0]).name()
         children = self.build_list(node.children[2])
         return Term(name, children[:])
 

prolog/interpreter/term.py

         return self
 
 class Callable(NonVar):
-    __slots__ = ("name", "signature")
     _immutable_ = True
-    name = ""
-    signature = ""
-
+    __slots__ = ()
+    
+    def name(self):
+        raise NotImplementedError("abstract base")
+        
+    def signature(self):
+        raise NotImplementedError("abstract base")
+        
     def get_prolog_signature(self):
         raise NotImplementedError("abstract base")
         
     @specialize.arg(3)
     def basic_unify(self, other, heap, occurs_check=False):
         if (isinstance(other, Callable) and
-            self.name == other.name and
+            self.name() == other.name() and
             self.argument_count() == other.argument_count()):
             for i in range(self.argument_count()):
                 self.argument_at(i).unify(other.argument_at(i), heap, occurs_check)
 
 class Atom(Callable):
     TYPE_STANDARD_ORDER = 1
-
+    # __slots__ = ('_name', '_signature')
     cache = {}
     _immutable_ = True
 
     def __init__(self, name):
-        self.name = name
-        self.signature = self.name + "/0"
+        self._name = name
+        self._signature = self._name + "/0"
 
     def __str__(self):
-        return self.name
+        return self.name()
 
     def __repr__(self):
-        return "Atom(%r)" % (self.name,)
+        return "Atom(%r)" % (self.name(),)
 
 
     def copy_and_basic_unify(self, other, heap, env):
         if isinstance(other, Atom) and (self is other or
-                                        other.name == self.name):
+                                        other.name() == self.name()):
             return self
         else:
             raise UnificationFailed
 
     def eval_arithmetic(self, engine):
         #XXX beautify that
-        if self.name == "pi":
+        if self.name() == "pi":
             return Float.pi
-        if self.name == "e":
+        if self.name() == "e":
             return Float.e
         error.throw_type_error("evaluable", self.get_prolog_signature())
         
     
     def argument_count(self):
         return 0
-
+        
+    def name(self):
+        return self._name
+        
+    def signature(self):
+        return self._signature
 
 class Number(NonVar): #, UnboxedValue):
     TYPE_STANDARD_ORDER = 2
     TYPE_STANDARD_ORDER = 3
     _immutable_ = True
     _immutable_fields_ = ["_args[*]"]
-
-    def __init__(self, name, args, signature=None):
-
-        self.name = name
+    __slots__ = ('_name', '_signature', '_args')
+    
+    def __init__(self, term_name, args, signature=None):
+        self._name = term_name
         self._args = make_sure_not_resized(args)
         if signature is None:
-            self.signature = name + "/" + str(len(args))
+            self._signature = term_name + "/" + str(len(args))
         else:
-            self.signature = signature
+            self._signature = signature
                     
     def __repr__(self):
-        return "Term(%r, %r)" % (self.name, self.arguments())
+        return "Term(%r, %r)" % (self.name(), self.arguments())
 
     def __str__(self):
-        return "%s(%s)" % (self.name, ", ".join([str(a) for a in self.arguments()]))
+        return "%s(%s)" % (self.name(), ", ".join([str(a) for a in self.arguments()]))
 
     def copy_and_basic_unify(self, other, heap, env):
         if (isinstance(other, Term) and
-                self.signature == other.signature):
+                self.signature() == other.signature()):
             return self._copy_term(_term_unify_and_standardize_apart,
                                    other, heap, env)
         else:
             args[i] = cloned
             i += 1
         if newinstance:
-            return Term(self.name, args, self.signature)
+            return Term(self.name(), args, self.signature())
         else:
             return self
 
     def get_prolog_signature(self):
-        return Term("/", [Atom.newatom(self.name),
+        return Term("/", [Atom.newatom(self.name()),
                                                 Number(self.argument_count())])
     
     def contains_var(self, var, heap):
     def eval_arithmetic(self, engine):
         from prolog.interpreter.arithmetic import get_arithmetic_function
 
-        func = get_arithmetic_function(self.signature)
+        func = get_arithmetic_function(self.signature())
         if func is None:
             error.throw_type_error("evaluable", self.get_prolog_signature())
         return func(engine, self)
         
     def argument_count(self):
         return len(self._args)
+        
+    def name(self):
+        return self._name
+        
+    def signature(self):
+        return self._signature
+        
 @specialize.argtype(0)
 def rcmp(a, b): # RPython does not support cmp...
     if a == b:
         return rcmp(compute_unique_id(obj1), compute_unique_id(obj2))
     if isinstance(obj1, Atom):
         assert isinstance(obj2, Atom)
-        return rcmp(obj1.name, obj2.name)
+        return rcmp(obj1.name(), obj2.name())
     if isinstance(obj1, Term):
         assert isinstance(obj2, Term)
         c = rcmp(obj1.argument_count(), obj2.argument_count())
         if c != 0:
             return c
-        c = rcmp(obj1.name, obj2.name)
+        c = rcmp(obj1.name(), obj2.name())
         if c != 0:
             return c
         for i in range(obj1.argument_count()):

prolog/interpreter/test/dont_test_translate.py

         e.run(t2)
         v0 = e.heap.getvar(0)
         if isinstance(v0, Atom):
-            return v0.name
-        return "no!"
+            return v0.name()        return "no!"
     assert run() == "a"
     t = Translation(run)
     t.annotate()

prolog/interpreter/test/test_builtin.py

     assert_true("assertz(f(a, a)).", e)
     assert_true("A = a, asserta(h(A, A)).", e)
     f = assert_true("g(B, B).", e)
-    assert f['B'].name == "b"
+    assert f['B'].name()== "b"
     f = assert_true("f(B, B).", e)
-    assert f['B'].name == "b"
+    assert f['B'].name()== "b"
     assert_false("h(c, c).", e)
     f = assert_true("h(B, B).", e)
-    assert f['B'].name == "a"
+    assert f['B'].name()== "a"
 
 @py.test.mark.xfail
 def test_assert_logical_update_view():

prolog/interpreter/test/test_callable_arg_interface.py

-from prolog.interpreter.parsing import parse_file, TermBuilder
-from prolog.interpreter.term import Atom, Number, Term
-import py
-
-def parse(inp):
-    t = parse_file(inp)
-    builder = TermBuilder()
-    return builder.build(t)
-    
-atom = parse('a.')[0]
-term = parse('t(a, b, c, d, f).')[0]
-def test_atom_get_signature():
-    r = atom.get_prolog_signature() 
-    r.name == '/'
-    r._args[0] == Atom('a')
-    r._args[1] == Number(0)
-
-def test_atom_get_arguments():
-    assert atom.arguments() == []
-    
-def test_atom_arguemtn_count():
-    assert atom.argument_count() == 0
-    
-def test_atom_get_argument_at():
-    assert py.test.raises(IndexError, 'atom.argument_at(0)')
-    
-def test_term_get_signature():
-    r = term.get_prolog_signature()
-    print r
-    assert r.name == '/'
-    assert r._args[0].name == 't'
-    assert r._args[1].num == 5
-    
-def test_term_get_arguments():
-    t = term.arguments()
-    assert isinstance(t, list)
-    assert len(t) == 5
-    
-def test_term_get_argument_out_of_range():
-    py.test.raises(IndexError, 'term.argument_at(5)')
-
-def test_term_get_argument_in_range():
-    t =  term.argument_at(2)
-    assert t.name == 'c'
-    
-def test_term_argument_count():
-    assert term.argument_count() == 5

prolog/interpreter/test/test_callable_interface.py

+from prolog.interpreter.parsing import parse_file, TermBuilder
+from prolog.interpreter.term import Atom, Number, Term, Callable
+import py
+
+def parse(inp):
+    t = parse_file(inp)
+    builder = TermBuilder()
+    return builder.build(t)
+    
+atom = parse('a.')[0]
+term = parse('t(a, b, c, d, f).')[0]
+def test_atom_get_signature():
+    r = atom.get_prolog_signature() 
+    r.name() == '/'
+    r._args[0] == Atom('a')
+    r._args[1] == Number(0)
+
+def test_atom_get_arguments():
+    assert atom.arguments() == []
+    
+def test_atom_arguemtn_count():
+    assert atom.argument_count() == 0
+    
+def test_atom_get_argument_at():
+    assert py.test.raises(IndexError, 'atom.argument_at(0)')
+    
+def test_term_get_signature():
+    r = term.get_prolog_signature()
+    print r
+    assert r.name() == '/'
+    assert r._args[0].name() == 't'
+    assert r._args[1].num == 5
+    
+def test_term_get_arguments():
+    t = term.arguments()
+    assert isinstance(t, list)
+    assert len(t) == 5
+    
+def test_term_get_argument_out_of_range():
+    py.test.raises(IndexError, 'term.argument_at(5)')
+
+def test_term_get_argument_in_range():
+    t =  term.argument_at(2)
+    assert t.name() == 'c'
+    
+def test_term_argument_count():
+    assert term.argument_count() == 5
+    
+def test_callable_name():
+    c = Callable()
+    py.test.raises(NotImplementedError, 'c.name()')
+    
+def test_callable_signature():
+    c = Callable()
+    py.test.raises(NotImplementedError, 'c.signature()')
+    
+def test_atom_name():
+    assert atom.name() == 'a'
+
+def test_atom_signature():
+    assert atom.signature() == 'a/0'
+    
+def test_term_name():
+    assert term.name() == 't'
+    
+def test_term_signature():
+    assert term.signature() == 't/5'

prolog/interpreter/test/test_continuation.py

     query = Term(",", [Term("f", [Var()]), Term("g", [Var()])])
     py.test.raises(error.UnificationFailed,
                    e.run_query, query, CollectContinuation())
-    assert all[0].argument_at(0).argument_at(0).name == "x"
-    assert all[0].argument_at(1).argument_at(0).name == "a"
-    assert all[1].argument_at(0).argument_at(0).name == "x"
-    assert all[1].argument_at(1).argument_at(0).name == "b"
-    assert all[2].argument_at(0).argument_at(0).name == "y"
-    assert all[2].argument_at(1).argument_at(0).name == "a"
-    assert all[3].argument_at(0).argument_at(0).name == "y"
-    assert all[3].argument_at(1).argument_at(0).name == "b"
+    assert all[0].argument_at(0).argument_at(0).name()== "x"
+    assert all[0].argument_at(1).argument_at(0).name()== "a"
+    assert all[1].argument_at(0).argument_at(0).name()== "x"
+    assert all[1].argument_at(1).argument_at(0).name()== "b"
+    assert all[2].argument_at(0).argument_at(0).name()== "y"
+    assert all[2].argument_at(1).argument_at(0).name()== "a"
+    assert all[3].argument_at(0).argument_at(0).name()== "y"
+    assert all[3].argument_at(1).argument_at(0).name()== "b"
 
 # ___________________________________________________________________
 # integration tests
     """)
     t, vars = get_query_and_vars("f(X).")
     e.run(t)
-    assert vars['X'].dereference(e.heap).name == "a"
+    assert vars['X'].dereference(e.heap).name()== "a"
 
 def test_and():
     e = get_engine("""
     e.run(parse_query_term("f(a, c)."))
     t, vars = get_query_and_vars("f(X, c).")
     e.run(t)
-    assert vars['X'].dereference(e.heap).name == "a"
+    assert vars['X'].dereference(e.heap).name()== "a"
 
 def test_and_long():
     e = get_engine("""
         """)
     t, vars = get_query_and_vars("f(a, b, Z).")
     e.run(t)
-    assert vars['Z'].dereference(e.heap).name == "a"
+    assert vars['Z'].dereference(e.heap).name()== "a"
     f = collect_all(e, "X = 1; X = 2.")
     assert len(f) == 2
 
     """)
     heaps = collect_all(e, "g(X).")
     assert len(heaps) == 3
-    assert heaps[0]['X'].name == "a"
-    assert heaps[1]['X'].name == "b"
-    assert heaps[2]['X'].name == "c"
+    assert heaps[0]['X'].name()== "a"
+    assert heaps[1]['X'].name()== "b"
+    assert heaps[2]['X'].name()== "c"
 
 def test_lists():
     e = get_engine("""

prolog/interpreter/test/test_function.py

 
 class C(Callable):
     def __init__(self, name):
-        self.name = name
+        self._name = name
     def __eq__(self, other):
-        return self.name == other.name
+        return self.name()== other.name()    
     def __str__(self):
-        return 'C(%s)' % self.name
+        return 'C(%s)' % self.name()    
+    def signature(self):
+        return self.name() + '/123'
+    def name(self):
+        return 'C'
     __repr__ = __str__
 def test_copy():
             

prolog/interpreter/test/test_parsing.py

     for fact in facts:
         print fact
         e.add_rule(fact)
-    assert e.signature2function["add_numeral/3"].rulechain.head.argument_at(1).name == "null"
+    assert e.signature2function["add_numeral/3"].rulechain.head.argument_at(1).name()== "null"
     four = Term("succ", [Term("succ", [Term("succ",
                 [Term("succ", [Atom("null")])])])])
     e.run(parse_query_term("numeral(succ(succ(null)))."))
     """)
     builder = TermBuilder()
     fact, = builder.build(t)
-    assert fact.argument_at(0).name == 'ASa0%!!231@~!@#%'
-    assert fact.argument_at(1).name == 'a'
-    assert fact.argument_at(2).name == '[]'
+    assert fact.argument_at(0).name()== 'ASa0%!!231@~!@#%'
+    assert fact.argument_at(1).name()== 'a'
+    assert fact.argument_at(2).name()== '[]'
     t = parse_file("""
         'a'.
         a.
     """)
     builder = TermBuilder()
     fact1, fact2, = builder.build(t)
-    assert fact1.name == fact2.name
-
+    assert fact1.name()== fact2.name()
 def test_parenthesis():
     t = parse_file("""
         g(X, Y) :- (g(x, y); g(a, b)), /* this too is a comment

prolog/interpreter/test/test_unification.py

     b = Var()
     heap = Heap()
     b.unify(Atom.newatom("hallo"), heap)
-    assert b.getvalue(heap).name == "hallo"
+    assert b.getvalue(heap).name()== "hallo"
     a = Var()
     b = Var()
     a.unify(b, heap)
     a.unify(Atom.newatom("hallo"), heap)
-    assert a.getvalue(heap).name == "hallo"
-    assert b.getvalue(heap).name == "hallo"
+    assert a.getvalue(heap).name()== "hallo"
+    assert b.getvalue(heap).name()== "hallo"
 
 def test_unify_var():
     b = Var()
     heap = Heap()
     print t1, t2
     t1.unify(t2, heap)
-    assert X.getvalue(heap).name == "HALLO"
-    assert Y.getvalue(heap).name == "hallo"
+    assert X.getvalue(heap).name()== "HALLO"
+    assert Y.getvalue(heap).name()== "hallo"
 
 def test_blackbox():
     bl1 = BlackBox()
     t1 = Term("f", [X, X, Term("g", [Y, X])])
     t2 = t1.enumerate_vars({})
     assert isinstance(t2, Term)
-    assert t2.signature == t1.signature
+    assert t2.signature()== t1.signature()    
     assert t2.argument_at(0) is t2.argument_at(1)
     assert t2.argument_at(0).num == 0
     assert t2.argument_at(2).argument_at(1).num == 0
                            Term("f", [Y, X])]))
     X = e.heap.newvar()
     e.run(Term("f", [Atom.newatom("b"), X]))
-    assert X.dereference(e.heap).name == "b"
+    assert X.dereference(e.heap).name()== "b"
     query = Term("f", [Atom.newatom("b"), Atom.newatom("a")]) 
     e.run(query)

prolog/interpreter/translatedmain.py

         if isinstance(t, term.Term):
             errorterm = t.argument_at(0)
             if isinstance(errorterm, term.Callable):
-                if errorterm.name == "instantiation_error":
+                if errorterm.name()== "instantiation_error":
                     printmessage("arguments not sufficiently instantiated\n")
                     return
-                elif errorterm.name == "existence_error":
+                elif errorterm.name()== "existence_error":
                     if isinstance(errorterm, term.Term):
                         printmessage("Undefined %s: %s\n" % (
                             f.format(errorterm.argument_at(0)),
                             f.format(errorterm.argument_at(1))))
                         return
-                elif errorterm.name == "domain_error":
+                elif errorterm.name()== "domain_error":
                     if isinstance(errorterm, term.Term):
                         printmessage(
                             "Domain error: '%s' expected, found '%s'\n" % (
                             f.format(errorterm.argument_at(0)),
                             f.format(errorterm.argument_at(1))))
                         return
-                elif errorterm.name == "type_error":
+                elif errorterm.name()== "type_error":
                     if isinstance(errorterm, term.Term):
                         printmessage(
                             "Type error: '%s' expected, found '%s'\n" % (
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.