Commits

Pierre Carbonnelle  committed ba989e5

simplify Literal.__init__

  • Participants
  • Parent commits e7ae52e

Comments (0)

Files changed (2)

File pyDatalog/pyDatalog.py

 
 class Variable(pyParser.VarSymbol, pyParser.LazyList):
     def __init__(self, name=None):
+        name = 'X%i' % id(self) if name is None else name
         pyParser.LazyList.__init__(self)
-        pyParser.VarSymbol.__init__(self, 'X%i' % id(self) if name is None else name)
+        pyParser.VarSymbol.__init__(self, name)
+        self.associated_symbol = pyParser.Symbol(name) # used to create literals
 pyDatalog.Variable = Variable
 
 """Keep a dictionary of classes with datalog capabilities.  This list is used by pyEngine to resolve prefixed literals."""

File pyDatalog/pyParser.py

         self.args = terms # TODO simplify
         self.todo = self
         cls_name = predicate_name.split('.')[0].replace('~','') if 1< len(predicate_name.split('.')) else ''
-        terms, env = [], {}
+        terms = []
         for i, arg in enumerate(self.args):
             if isinstance(arg, pyDatalog.Variable):
                 arg.todo = self
                 del arg._data[:] # reset variables
-                # deal with (X,X)
-                variable = env.get(id(arg), Symbol(arg._pyD_name))
-                env[id(arg)] = variable
-                terms.append(variable)
+                terms.append(arg.associated_symbol)
             elif isinstance(arg, Symbol):
                 terms.append(arg)
             elif isinstance(arg, Literal):