Exemplo n.º 1
0
Arquivo: core.py Projeto: jdmcbr/logpy
def reify(e, s):
    if isvar(e):
        return walkstar(e, s)
    elif isinstance(e, tuple):
        return tuple(reify(arg, s) for arg in e)
    else:
        return e
Exemplo n.º 2
0
Arquivo: core.py Projeto: jdmcbr/logpy
def run(n, x, *goals):
    """ 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
    >>> run(1, x, eq(x, 1))
    (1,)
    """
    return take(n, unique(walkstar(x, s) for s in bindstar(({},), *goals)))
Exemplo n.º 3
0
def reify(e, s):
    """ Replace variables of expression with substitution

    >>> e = (1, x, (3, y))
    >>> s = {x: 2, y: 4}
    >>> reify(e, s)
    (1, 2, (3, 4))
    """
    if isvar(e):
        return walkstar(e, s)
    elif isinstance(e, tuple):
        return tuple(reify(arg, s) for arg in e)
    else:
        return e