Commits

Pierre Carbonnelle committed 2205e55

fix error in precalculations of a function of a function

Comments (0)

Files changed (2)

pyDatalog/examples/test.py

         assert ask(f[a]==X) == set([('c',)])
         
         + (f[a]==a)
+        assert ask(f[X]==Y) == set([('a', 'a')])
         assert ask(f[f[a]]==X) == set([('a',)])
         assert ask(f[X]==f[a]) == set([('a',)])
         assert ask(f[X]==f[a]+'') == set([('a',)])
         + (f[c]==c)
-        assert ask(f[f[a]]==X) == set([('a',), ('c',)])
+        assert ask(f[f[a]]==X) == set([('a',)])
         - (f[c]==c)
         - (f[a]==a)
         assert ask(f[f[a]]==X) == None

pyDatalog/pyParser.py

     # logic shared by Symbol and Function 
     new_args, pre_calculations = [], Body()
     for arg in args:
-        if isinstance(arg, Operation):
+        if isinstance(arg, (Operation, Function)):
             pre_calculations = pre_calculations & arg._precalculation()
             new_args.append(arg)
-        elif isinstance(arg, (Operation, Function)):
-            Y = Function.newSymbol()
-            new_args.append(Y)
-            pre_calculations = pre_calculations & (Y == arg)
         else:
             new_args.append(arg)
     return new_args, pre_calculations
                 elif isinstance(other, (Operation, Function)): # a.p[X]<Y+Z transformed into (Y2==Y+Z) & (a.p[X]<Y2)
                     Y2 = Function.newSymbol()
                     return (Y2 == other) & Literal.make(self.name + operator, list(self.keys) + [Y2], prearity=len(self.keys))
-            return Literal.make(self.name + operator, list(self.keys) + [other], prearity=len(self.keys))
+            literal = Literal.make(self.name + operator, list(self.keys) + [other], prearity=len(self.keys))
+            literal.pre_calculations = self.pre_calculations & other._precalculation() #TODO write more tests
+            return literal
         else:
             if not isinstance(other, Expression):
                 raise util.DatalogError("Syntax error: Symbol or Expression expected", None, None)
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.