Ejemplo n.º 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)))
Ejemplo n.º 2
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 isTaggedList(exp, tag):
    """Returns true if the expression is tagged with the 'tag'."""
    if pair.isList(exp) and pair.length(exp) > 0:
        return pair.car(exp) == tag
    return 0
def operator(exp):
    if pair.length(exp) == 0:
        raise SchemeError, \
              "No operator given for procedure application -- OPERATOR"
    return pair.car(exp)
Ejemplo n.º 5
0
def isTaggedList(exp, tag):
    """Returns true if the expression is tagged with the 'tag'."""
    if pair.isList(exp) and pair.length(exp) > 0:
        return pair.car(exp) == tag
    return 0
Ejemplo n.º 6
0
def operator(exp):
    if pair.length(exp) == 0:
        raise SchemeError, \
              "No operator given for procedure application -- OPERATOR"
    return pair.car(exp)