def teval(exp, env, cont): """Evaluates an expression 'exp' in an environment 'env'. Exercise 4.3 asks us to rewrite this in a more natural data-directed manner. Pychecker, also, doesn't like seeing so many 'return' statements in one function. *grin* """ if expressions.isSelfEvaluating(exp): return pogo.bounce(cont, exp) if expressions.isVariable(exp): return pogo.bounce(cont, environment.lookupVariableValue(exp, env)) if expressions.isQuoted(exp): return evalQuoted(exp, env, cont) if expressions.isAssignment(exp): return evalAssignment(exp, env, cont) if expressions.isDefinition(exp): return evalDefinition(exp, env, cont) if expressions.isIf(exp): return evalIf(exp, env, cont) if expressions.isLambda(exp): return pogo.bounce(cont, expressions.makeProcedure (expressions.lambdaParameters(exp), expressions.lambdaBody(exp), env)) if expressions.isBegin(exp): return evalSequence(expressions.beginActions(exp), env, cont) if expressions.isApplication(exp): return evalApplication(exp, env, cont) raise SchemeError, "Unknown expression type -- eval " + str(exp)
def teval(exp, env, cont): """Evaluates an expression 'exp' in an environment 'env'. Exercise 4.3 asks us to rewrite this in a more natural data-directed manner. Pychecker, also, doesn't like seeing so many 'return' statements in one function. *grin* """ if expressions.isSelfEvaluating(exp): return pogo.bounce(cont, exp) if expressions.isVariable(exp): return pogo.bounce(cont, environment.lookupVariableValue(exp, env)) if expressions.isQuoted(exp): return evalQuoted(exp, env, cont) if expressions.isAssignment(exp): return evalAssignment(exp, env, cont) if expressions.isDefinition(exp): return evalDefinition(exp, env, cont) if expressions.isIf(exp): return evalIf(exp, env, cont) if expressions.isLambda(exp): return pogo.bounce( cont, expressions.makeProcedure(expressions.lambdaParameters(exp), expressions.lambdaBody(exp), env)) if expressions.isBegin(exp): return evalSequence(expressions.beginActions(exp), env, cont) if expressions.isApplication(exp): return evalApplication(exp, env, cont) raise SchemeError, "Unknown expression type -- eval " + str(exp)
def analyzed(env, cont): return pogo.bounce(cont, expressions.makeProcedure(params, analyzedBody, env))