예제 #1
0
 def execute_proc(arguments, fail0):
     body_env = extend_environment(names, arguments,
                                   procedure_environment(procedure))
     if TRACE_APPLICATIONS:
         display(cons(procedure_name(procedure), arguments))
         display(body_env)
         print()
     return continue_with(
         body_exec,
         body_env,
         succeed,
         fail0,
     )
예제 #2
0
파일: syntax.py 프로젝트: mbillingr/sdf
def make_begin(actions):
    return cons(Symbol("begin"), actions)
예제 #3
0
파일: syntax.py 프로젝트: mbillingr/sdf
def make_lambda(parameters, body):
    return cons(
        Symbol("lambda"),
        cons(parameters,
             begin_actions(body) if is_begin(body) else (body, )),
    )
예제 #4
0
파일: syntax.py 프로젝트: mbillingr/sdf
def definition_value(defn):
    if is_variable(cadr(defn)):
        return caddr(defn)
    else:
        return cons(symbol("lambda"), cons(cdadr(defn), cddr(defn)))
예제 #5
0
def let_to_combination(let_exp):
    names = let_bound_variables(let_exp)
    values = let_bound_values(let_exp)
    body = let_body(let_exp)
    return cons(make_lambda(names, body), values)
예제 #6
0
def initialize_repl():
    global THE_GLOBAL_ENVIRONMENT
    THE_GLOBAL_ENVIRONMENT = make_initial_environment()


def check_repl_initialized():
    if THE_GLOBAL_ENVIRONMENT == "not initialized":
        raise RuntimeError("Interpreter not initialized. Run init() first.")


if __name__ == "__main__":
    a = Symbol("a")
    b = Symbol("b")
    c = Symbol("c")

    print((a, b, c))

    print(car((1, 2, 3)), cdr((1, 2, 3)))
    x = cons(1, (2, 3, 4))
    print(x)
    print(car(x), cdr(x), cdr(cdr(x)))

    quote = Symbol("quote")
    x = Symbol("x")
    begin = Symbol("begin")

    # print(g.eval(((Symbol('lambda'), (x,), x), 42), ()))
    print(g.eval((begin, 1, 2, 3), ()))

    init()
예제 #7
0
 def execute_proc(args, fail0):
     if TRACE_APPLICATIONS:
         display(cons(symbol("<primitive>"), args))
         print()
     return continue_with(succeed,
                          apply_primitive_procedure(procedure, args), fail0)
예제 #8
0
 def execute_proc(args, fail0):
     if TRACE_APPLICATIONS:
         display(cons(symbol("<continuation>"), args))
         print()
     return continue_with(continuation.succeed, *args, continuation.fail)