def analyze(exp): """analyze(exp) -> lambda env, cont: ... Given an expression, returns a new lambda function that can be applied on an environment and continuation.""" if expressions.isSelfEvaluating(exp): return analyzeSelfEvaluating(exp) if expressions.isVariable(exp): return analyzeVariable(exp) if expressions.isQuoted(exp): return analyzeQuoted(exp) if expressions.isAssignment(exp): return analyzeAssignment(exp) if expressions.isDefinition(exp): return analyzeDefinition(exp) if expressions.isIf(exp): return analyzeIf(exp) if expressions.isLambda(exp): return analyzeLambda(exp) if expressions.isBegin(exp): return analyzeBegin(exp) ## Application checking must come last, after all the special forms. ## have been tested. if expressions.isApplication(exp): return analyzeApplication(exp) ## And if we get here, bad things have happened. raise SchemeError, ("Unknown expression type -- eval " + expressions.toString(exp))
def schemeWrite(thing): sys.stdout.write(expressions.toString(thing, quoteStrings=1)) return Symbol("ok")
def promptCallback(s): try: print expressions.toString(interp.eval(parser.parse(s))) except (error.SchemeError, parser.ParserError), e: print "ERROR (%s): %s" % (e.__class__, e)