def expand_clauses(clauses): if clauses is EmptyList: return Boolean(False) first = car(clauses) rest = cdr(clauses) if is_cond_else_clause(first): if rest is EmptyList: return sequence_expr(cond_actions(first)) else: raise ValueError('ELSE caluse isn\'t last: %s' % clauses) else: return make_if(cond_predicate(first), sequence_expr(cond_actions(first)), expand_clauses(rest))
def rest_operands(ops): return cdr(ops)
def operands(expr): return cdr(expr)
def rest_exprs(seq): return cdr(seq)
def is_last_expr(seq): return cdr(seq) is EmptyList
def begin_actions(expr): return cdr(expr)
def inner(arg, count): if arg is EmptyList: return count return inner(cdr(arg), count + 1)
def cond_clauses(expr): return cdr(expr)
def cond_actions(clause): return cdr(clause)
def inner(expr): if expr is EmptyList: return EmptyList return cons(cadar(expr), inner(cdr(expr)))