Exemple #1
0
def OR_handler(exp):
    """We have to consider three cases:

    (OR)            ===>   #t

    (OR e1)         ===>   e1

    (OR e1 e2 ...)  ===>   (let ((temp-val e1))
                              (IF temp-val
                                  temp-val
                                  (OR e2 ...)))

                    ===>  ((lambda (temp-val)
                              (IF temp-val
                                  temp-val
                                  (OR e2 ...)))
                           e1)
    """
    clauses = and_clauses(exp)
    if pair.length(clauses) == 0:
        return symbol.true
    elif pair.length(clauses) == 1:
        return pair.car(clauses)
    else:
        temporarySymbol = symbol.makeUniqueTemporary()
        lambdaVal = expressions.makeLambda(
            pair.list(temporarySymbol),
            pair.list(expressions.makeIf(temporarySymbol,
                                         temporarySymbol,
                                         makeOr(pair.cdr(clauses)))))
        return expressions.makeApplication(
            lambdaVal, pair.list(pair.car(clauses)))
Exemple #2
0
 def c_car(carString):
     def c_cdr(cdrString):
         pieces.append(carString)
         pieces.append(".")
         pieces.append(cdrString)
         return pogo.bounce(loop_cont, pieces)
     return t_expressionToString(pair.cdr(loop_exp), c_cdr)
 def fromscheme(self, val, shallow=False):
     "Convert a Scheme value to a Python value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda(val, self, shallow)
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return orig
         return schemepy.types.Lambda(val, self, shallow)
     if symbol.isSymbol(val):
         if val == symbol.true:
             return True
         if val == symbol.false:
             return False
         return schemepy.types.Symbol(str(val))
     if pair.isNull(val):
         return []
     if isAList(val):
         dic = {}
         while not pair.isNull(val):
             el = pair.car(val)
             key = self.fromscheme(pair.car(el))
             value = pair.cdr(el)
             if not shallow:
                 value = self.fromscheme(value)
             dic[key] = value
             val = pair.cdr(val)
         return dic
     if pair.isList(val):
         lst = []
         while not pair.isNull(val):
             el = pair.car(val)
             if not shallow:
                 el = self.fromscheme(el)
             lst.append(el)
             val = pair.cdr(val)
         return lst
     if pair.isPair(val):
         car = pair.car(val)
         cdr = pair.cdr(val)
         if not shallow:
             car = self.fromscheme(car)
             cdr = self.fromscheme(cdr)
         return schemepy.types.Cons(car, cdr)
     return val
                def c_car(carString):
                    def c_cdr(cdrString):
                        pieces.append(carString)
                        pieces.append(".")
                        pieces.append(cdrString)
                        return pogo.bounce(loop_cont, pieces)

                    return t_expressionToString(pair.cdr(loop_exp), c_cdr)
Exemple #5
0
 def fromscheme(self, val, shallow=False):
     "Convert a Scheme value to a Python value."
     if expressions.isCompoundProcedure(val):
         return schemepy.types.Lambda(val, self, shallow)
     if expressions.isPrimitiveProcedure(val):
         fun = expressions.primitiveImplementation(val)
         orig = fun.__dict__.get("_orig", None)
         if orig and callable(orig):
             return orig
         return schemepy.types.Lambda(val, self, shallow)
     if symbol.isSymbol(val):
         if val == symbol.true:
             return True
         if val == symbol.false:
             return False
         return schemepy.types.Symbol(str(val))
     if pair.isNull(val):
         return []
     if isAList(val):
         dic = {}
         while not pair.isNull(val):
             el = pair.car(val)
             key = self.fromscheme(pair.car(el))
             value = pair.cdr(el)
             if not shallow:
                 value = self.fromscheme(value)
             dic[key] = value
             val = pair.cdr(val)
         return dic
     if pair.isList(val):
         lst = []
         while not pair.isNull(val):
             el = pair.car(val)
             if not shallow:
                 el = self.fromscheme(el)
             lst.append(el)
             val = pair.cdr(val)
         return lst
     if pair.isPair(val):
         car = pair.car(val)
         cdr = pair.cdr(val)
         if not shallow:
             car = self.fromscheme(car)
             cdr = self.fromscheme(cdr)
         return schemepy.types.Cons(car, cdr)
     return val
def expandClauses(clauses):
    if pair.isNull(clauses):
        return false
    first = pair.car(clauses)
    rest = pair.cdr(clauses)
    if isCondElseClause(first):
        if pair.isNull(rest):
            return sequenceToExp(condActions(first))
        raise SchemeError, "else clause isn't last -- condToIf" + clauses
    return makeIf(condPredicate(first), sequenceToExp(condActions(first)),
                  expandClauses(rest))
Exemple #7
0
def isAList(lst):
    """\
    Check whether the pyscheme list lst is an associate list
    """
    while not pair.isNull(lst):
        if not pair.isPair(lst):
            return False
        if not pair.isPair(pair.car(lst)):
            return False
        lst = pair.cdr(lst)
    return True
def isAList(lst):
    """\
    Check whether the pyscheme list lst is an associate list
    """
    while not pair.isNull(lst):
        if not pair.isPair(lst):
            return False
        if not pair.isPair(pair.car(lst)):
            return False
        lst = pair.cdr(lst)
    return True
Exemple #9
0
def expandClauses(clauses):
    if pair.isNull(clauses):
        return false
    first = pair.car(clauses)
    rest = pair.cdr(clauses)
    if isCondElseClause(first):
        if pair.isNull(rest):
            return sequenceToExp(condActions(first))
        raise SchemeError, "else clause isn't last -- condToIf" + clauses
    return makeIf(condPredicate(first),
                  sequenceToExp(condActions(first)),
                  expandClauses(rest))
Exemple #10
0
def AND_handler(exp):
    """We have to consider three cases:

    (AND)            ===>   #f
    (AND e1)         ===>   e1
    (AND e1 e2 ...)  ===>   (IF e1 (AND e2 ...)  #f)
    """
    clauses = and_clauses(exp)
    if pair.length(clauses) == 0:
        return symbol.false
    elif pair.length(clauses) == 1:
        return pair.car(clauses)
    else:
        return expressions.makeIf(pair.car(clauses),
                                  makeAnd(pair.cdr(clauses)),
                                  symbol.false)
def definitionValue(exp):
    if isSymbol(pair.cadr(exp)):
        return pair.caddr(exp)
    return makeLambda(pair.cdr(pair.cadr(exp)), pair.cddr(exp))
def beginActions(exp):
    return pair.cdr(exp)
def letBindingValues(bindings):
    if pair.isNull(bindings): return pair.list()
    return pair.cons(pair.cadr(pair.car(bindings)),
                     letBindingValues(pair.cdr(bindings)))
def letBody(exp):
    return pair.cdr(pair.cdr(exp))
def condClauses(exp):
    return pair.cdr(exp)
Exemple #16
0
 def isLoopyPair(expr):
     return (pair.isPair(expr) and
             id(pair.cdr(expr)) in seenExpressionIds)
Exemple #17
0
def letBody(exp):
    return pair.cdr(pair.cdr(exp))
def operands(exp):
    return pair.cdr(exp)
Exemple #19
0
def operands(exp):
    return pair.cdr(exp)
Exemple #20
0
def restExps(seq):
    return pair.cdr(seq)
Exemple #21
0
def restOperands(ops):
    return pair.cdr(ops)
Exemple #22
0
 def c_car(carString):
     pieces.append(carString)
     return pogo.bounce(loop, pair.cdr(loop_exp), loop_cont)
Exemple #23
0
def condClauses(exp):
    return pair.cdr(exp)
def isLastExp(seq):
    return pair.isNull(pair.cdr(seq))
Exemple #25
0
def isLastExp(seq):
    return pair.isNull(pair.cdr(seq))
def restExps(seq):
    return pair.cdr(seq)
Exemple #27
0
def beginActions(exp):
    return pair.cdr(exp)
def restOperands(ops):
    return pair.cdr(ops)
Exemple #29
0
def definitionValue(exp):
    if isSymbol(pair.cadr(exp)):
        return pair.caddr(exp)
    return makeLambda(pair.cdr(pair.cadr(exp)),
                      pair.cddr(exp))
def condActions(clause):
    return pair.cdr(clause)
Exemple #31
0
def condActions(clause):
    return pair.cdr(clause)
 def isLoopyPair(expr):
     return (pair.isPair(expr) and id(pair.cdr(expr)) in seenExpressionIds)
Exemple #33
0
def and_clauses(exp):
    return pair.cdr(exp)
 def c_car(carString):
     pieces.append(carString)
     return pogo.bounce(loop, pair.cdr(loop_exp), loop_cont)
Exemple #35
0
def letBindingValues(bindings):
    if pair.isNull(bindings): return pair.list()
    return pair.cons(pair.cadr(pair.car(bindings)),
                           letBindingValues(pair.cdr(bindings)))