Pierre Carbonnelle avatar Pierre Carbonnelle committed ba989e5

simplify Literal.__init__

Comments (0)

Files changed (2)

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."""

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):
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.