def setupEnvironment(): """Sets up a new environment with a bunch of fairly standard Scheme built-in primitives.""" PRIMITIVE_PROCEDURES = [ ["car", pair.car], ["cdr", pair.cdr], ["cons", pair.cons], ["append", pair.append], ["list", pair.list], ["set-car!", pair.setCarBang], ["set-cdr!", pair.setCdrBang], ["+", schemeAdd], ["-", schemeSubtract], ["*", schemeMultiply], ["/", schemeDivide], ["remainder", schemeRemainder], ["quotient", schemeQuotient], ["sqrt", schemeSqrt], ["floor", schemeFloor], ["ceiling", schemeCeiling], ["=", schemeNumericalEq], ["<", schemeLessThan], ["<=", schemeLessThanOrEquals], [">", schemeGreaterThan], [">=", schemeGreaterThanOrEquals], ["eq?", schemeEqQuestion], ["equal?", schemeEqualQuestion], ["list?", schemeListQuestion], ["pair?", schemePairQuestion], ["null?", schemeNullQuestion], ["display", schemeDisplay], ["write", schemeWrite], ["newline", schemeNewline], ["not", schemeNot], ["string->symbol", schemeStringToSymbol], ["symbol->string", schemeSymbolToString], ["number->string", schemeNumberToString], ["string-append", schemeStringAppend], ["quit", schemeQuit], ["exit", schemeQuit], ["error", schemeError], ["parse", schemeParse], ["pow", schemePower], ] initial_environment = environment.extendEnvironment( pair.NIL, pair.NIL, environment.THE_EMPTY_ENVIRONMENT) for name, proc in PRIMITIVE_PROCEDURES: installPythonFunction(name, proc, initial_environment) ## Finally, put true and false in there. environment.defineVariable(Symbol("#t"), Symbol("#t"), initial_environment) environment.defineVariable(Symbol("#f"), Symbol("#f"), initial_environment) return initial_environment
def installPythonFunction(name, function, env, wrapDefaults=True): """Installs a new Python function as a primitive into the given environment 'env'""" if wrapDefaults: wrappedProcedure = expressions.makePrimitiveProcedure( wrapPrimitiveWithDefaults(function)) else: wrappedProcedure = expressions.makePrimitiveProcedure(function) environment.defineVariable(Symbol(name), wrappedProcedure, env)
def setUp(self): ## We set up a VERY minimal environment here for some tests. ## We also set the recursion limit to something dreadful to see that ## call/cc is doing the right thing. ## ## Note: these tests directly work with analyzer.eval, and not ## through the nicer scheme.AnalyzingInterpreter interface. self.env = extendEnvironment(pair.list(Symbol('pi')), pair.list(3.1415926), THE_EMPTY_ENVIRONMENT) defineVariable(Symbol("#t"), Symbol("#t"), self.env) defineVariable(Symbol("#f"), Symbol("#f"), self.env) self.old_recursion_limit = sys.getrecursionlimit() sys.setrecursionlimit(100)
def c(val): environment.defineVariable( expressions.definitionVariable(exp), val, env) return pogo.bounce(cont, Symbol("ok"))
def define(self, name, value): """Define a variable in Scheme""" name = schemepy.types.Symbol(name) environment.defineVariable(self.toscheme(name), value, self._interp.get_environment())
def c(defVal): environment.defineVariable(defName, defVal, env) return pogo.bounce(cont, Symbol("ok"))
def c(val): environment.defineVariable(expressions.definitionVariable(exp), val, env) return pogo.bounce(cont, Symbol("ok"))