Beispiel #1
0
 def anygoal(s):
     reifiedgoals = (reify(goal, s) for goal in goals)
     def f(goals):
         for goal in goals:
             try:
                 yield goaleval(goal)(s)
             except EarlyGoalError:
                 pass
     return unique(interleave(f(reifiedgoals), [EarlyGoalError]),
                   key=dicthash)
Beispiel #2
0
    def anygoal(s):
        reifiedgoals = (reify(goal, s) for goal in goals)

        def f(goals):
            for goal in goals:
                try:
                    yield goaleval(goal)(s)
                except EarlyGoalError:
                    pass

        return unique(interleave(f(reifiedgoals), [EarlyGoalError]),
                      key=dicthash)
Beispiel #3
0
def run(n, x, *goals, **kwargs):
    """ Run a logic program.  Obtain n solutions to satisfy goals.

    n     - number of desired solutions.  See ``take``
            0 for all
            None for a lazy sequence
    x     - Output variable
    goals - a sequence of goals.  All must be true

    >>> from logpy import run, var, eq
    >>> x = var()
    >>> run(1, x, eq(x, 1))
    (1,)
    """
    return take(n,
                unique(reify(x, s) for s in goaleval(lallearly(*goals))({})))
Beispiel #4
0
def run(n, x, *goals, **kwargs):
    """ Run a logic program.  Obtain n solutions to satisfy goals.

    n     - number of desired solutions.  See ``take``
            0 for all
            None for a lazy sequence
    x     - Output variable
    goals - a sequence of goals.  All must be true

    >>> from logpy import run, var, eq
    >>> x = var()
    >>> run(1, x, eq(x, 1))
    (1,)
    """
    results = (reify(x, s) for s in goaleval(lallearly(*goals))({}))
    return take(n, unique(results, key=multihash))
Beispiel #5
0
 def allgoal(s):
     g = goaleval(reify(goals[0], s))
     return unique(interleave(
         goaleval(reify((lall, ) + tuple(goals[1:]), ss))(ss)
         for ss in g(s)),
                   key=dicthash)
Beispiel #6
0
 def allgoal(s):
     g = goaleval(reify(goals[0], s))
     return unique(interleave(
                     goaleval(reify((lall,) + tuple(goals[1:]), ss))(ss)
                     for ss in g(s)),
                   key=dicthash)