Pierre Carbonnelle  committed 189aabf

remove "merge" function

  • Participants
  • Parent commits 59cd787
  • Branches default

Comments (0)

Files changed (1)

File pyDatalog/

                 env = e1.unify(e2, env)
                 if env == None: return env
         return env
+    # def match is not needed here
     def __str__(self): 
         return "'%s'" % str([str(e) for e in])
     tag = literal.get_tag()
-def merge(subgoal):
-[subgoal.literal.get_tag()] = subgoal
 class Subgoal(object):
 # op codes
-MERGE = 3
 # Schedule a task for later invocation
 def schedule(task):
+    if not isinstance(task, Thunk) and task[0] is SEARCH:
+[task[1].literal.get_tag()] = task[1]
 def complete(subgoal, post_thunk):
     Ts =
     Ts.Stack.append((Ts.Subgoals, Ts.Tasks, Ts.Goal)) # save the environment to the stack. Invoke will eventually do the Stack.pop().
     Ts.Subgoals, Ts.Tasks, Ts.Goal = {}, list(), subgoal
-    schedule((MERGE, subgoal))
+    schedule((SEARCH, subgoal))
     # prepend post_thunk at one level lower in the Stack, 
     # so that it is run immediately by invoke() after the search() thunk is complete
     if Logging: logging.debug('push')
 def invoke(subgoal):
     """ Invoke the tasks. Each task may append new tasks on the schedule."""
     Ts =
-    Ts.Tasks, Ts.Subgoals, Ts.Goal = list([(SEARCH, subgoal),]), {}, subgoal
+    Ts.Tasks, Ts.Subgoals, Ts.Goal = list(), {}, subgoal
+    schedule((SEARCH, subgoal))
     while (Ts.Tasks or Ts.Stack) and not Ts.Goal.is_done:
         while Ts.Tasks and not Ts.Goal.is_done:
             todo = Ts.Tasks.pop()
             elif todo[0] is ADD_CLAUSE:
-            elif todo[0] is MERGE:
-                merge(todo[1])
-                search(todo[1])
         if Ts.Stack: 
             Ts.Subgoals, Ts.Tasks, Ts.Goal = Ts.Stack.pop()
             if Logging: logging.debug('pop')
         sg = Subgoal(selected)
         sg.waiters.append(Waiter(subgoal, clause))
-        merge(sg)
         return schedule((SEARCH, sg))
 def add_clause(subgoal, clause):
         if literal.pred.prim: # X==Y, X < Y+Z
             if Logging : logging.debug("pyDatalog uses comparison primitive for %s" % literal)
-            return literal.pred.prim(literal, subgoal)
+            literal.pred.prim(literal, subgoal)
+            return
         elif literal.aggregate:
             if Logging : logging.debug("pyDatalog uses aggregate primitive for %s" % literal)
             base_terms = list(terms[:-1])
 def _(literal):
     subgoal = Subgoal(literal)
-    merge(subgoal)
     if subgoal.facts is True:
         return True
-# Other parts of the Datalog system depend on the equality primitive,
-# so carefully consider any modifications to it.
 def equals_primitive(literal, subgoal):
     x = literal.terms[0]
     y = literal.terms[1]