예제 #1
0
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
예제 #2
0
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
예제 #3
0
def apply(procedure, arguments, env, cont):
    """Applies a procedure on a list of arguments."""
    if expressions.isPrimitiveProcedure(procedure):
        return applyPrimitiveProcedure(procedure, arguments, env, cont)
    elif expressions.isContinuationProcedure(procedure):
        return applyContinuationProcedure(procedure, arguments)
    if expressions.isCompoundProcedure(procedure):
        newEnv = environment.extendEnvironment(
            expressions.procedureParameters(procedure), arguments,
            expressions.procedureEnvironment(procedure))
        return evalSequence(expressions.procedureBody(procedure), newEnv, cont)
    raise SchemeError, "Unknown procedure type -- apply " + str(procedure)
예제 #4
0
파일: evaluator.py 프로젝트: EvelynHf/basil
def apply(procedure, arguments, env, cont):
    """Applies a procedure on a list of arguments."""
    if expressions.isPrimitiveProcedure(procedure):
        return applyPrimitiveProcedure(procedure, arguments, env, cont)
    elif expressions.isContinuationProcedure(procedure):
        return applyContinuationProcedure(procedure, arguments)
    if expressions.isCompoundProcedure(procedure):
        newEnv = environment.extendEnvironment(
            expressions.procedureParameters(procedure),
            arguments,
            expressions.procedureEnvironment(procedure))
        return evalSequence(expressions.procedureBody(procedure), newEnv, cont)
    raise SchemeError, "Unknown procedure type -- apply " + str(procedure)
예제 #5
0
    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)
예제 #6
0
    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)
예제 #7
0
 def get_environment(self):
     return environment.extendEnvironment(pair.list(), pair.list(),
                                          environment.THE_EMPTY_ENVIRONMENT)
예제 #8
0
파일: scheme.py 프로젝트: EvelynHf/basil
 def get_environment(self):
     return environment.extendEnvironment(pair.list(), pair.list(), environment.THE_EMPTY_ENVIRONMENT)