Exemplo n.º 1
0
def inverse_eval(x):
    if isinstance(x, Value):
        result = x.inverse_eval()
    elif isinstance(x, basestring) or isinstance(x, _NUMBER_TYPES):
        result = x
    elif isinstance(x, tuple):
        if None in x:  # NULL ELEMENT
            (full, nullvalue) = inversePartial(self)
            result = PARTIAL_SYMBOL.structure(inverse_eval(full),
                                              inverse_eval(nullvalue))
        else:
            elts = [inverse_eval(elt) for elt in x]
            if None in elts:
                result = None  # if we allow inverse_eval to return None
            else:
                result = tuple(elts)
    else:
        result = reg_inverse_eval(x)
    if result is None:
        try:
            info = str(x)
        except:
            info = "object of type %r" % type(x)
        msg = "Cannot run inverse_eval on " + info
        print "WARNING:", msg
        return INVALID_SYMBOL.structure(msg)
    else:
        return result
Exemplo n.º 2
0
def inverse_eval(x):
    if isinstance(x, Value):
        result = x.inverse_eval()
    elif isinstance(x, basestring) or isinstance(x, _NUMBER_TYPES):
        result = x
    elif isinstance(x, tuple):
        if None in x:  # NULL ELEMENT
            (full, nullvalue) = inversePartial(self)
            result = PARTIAL_SYMBOL.structure(inverse_eval(full), inverse_eval(nullvalue))
        else:
            elts = [inverse_eval(elt) for elt in x]
            if None in elts:
                result = None  # if we allow inverse_eval to return None
            else:
                result = tuple(elts)
    else:
        result = reg_inverse_eval(x)
    if result is None:
        try:
            info = str(x)
        except:
            info = "object of type %r" % type(x)
        msg = "Cannot run inverse_eval on " + info
        print "WARNING:", msg
        return INVALID_SYMBOL.structure(msg)
    else:
        return result
Exemplo n.º 3
0
    def inverse_eval(self):
        if None in self:  # NULL ELEMENT
            from spark.lang.builtin import inversePartial, PARTIAL_SYMBOL

            (full, nullvalue) = inversePartial(self)
            return PARTIAL_SYMBOL.structure(inverse_eval(full), inverse_eval(nullvalue))

        def switch(arg):
            ie = inverse_eval(arg)
            if isStructure(ie):
                if ie.functor == BACKQUOTE_SYMBOL:
                    return ie[0]
            elif isinstance(ie, int) or isinstance(ie, float) or isinstance(ie, basestring):  # should use Integer, etc.
                return ie
            # otherwise
            return PREFIX_COMMA_SYMBOL.structure(ie)

        args = [switch(arg) for arg in self._args]
        return BACKQUOTE_SYMBOL.structure(_Structure(self.functor, args))
Exemplo n.º 4
0
    def inverse_eval(self):
        if None in self:  # NULL ELEMENT
            from spark.lang.builtin import inversePartial, PARTIAL_SYMBOL
            (full, nullvalue) = inversePartial(self)
            return PARTIAL_SYMBOL.structure(inverse_eval(full),
                                            inverse_eval(nullvalue))

        def switch(arg):
            ie = inverse_eval(arg)
            if isStructure(ie):
                if ie.functor == BACKQUOTE_SYMBOL:
                    return ie[0]
            elif isinstance(ie, int) or isinstance(ie, float) \
                 or isinstance(ie, basestring): # should use Integer, etc.
                return ie
            # otherwise
            return PREFIX_COMMA_SYMBOL.structure(ie)

        args = [switch(arg) for arg in self._args]
        return BACKQUOTE_SYMBOL.structure(_Structure(self.functor, args))