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 t_expand_lambda(self, expr, cont): parameters = expressions.lambdaParameters(expr) body = expressions.lambdaBody(expr) def c_expanded(expandedBody): return pogo.bounce(cont, expressions.makeLambda(parameters, expandedBody)) return pogo.bounce(self.t_expand, body, c_expanded)
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 analyzeLambda(exp): params = expressions.lambdaParameters(exp) analyzedBody = analyzeSequence(expressions.lambdaBody(exp)) def analyzed(env, cont): return pogo.bounce(cont, expressions.makeProcedure(params, analyzedBody, env)) return analyzed