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, )
def make_begin(actions): return cons(Symbol("begin"), actions)
def make_lambda(parameters, body): return cons( Symbol("lambda"), cons(parameters, begin_actions(body) if is_begin(body) else (body, )), )
def definition_value(defn): if is_variable(cadr(defn)): return caddr(defn) else: return cons(symbol("lambda"), cons(cdadr(defn), cddr(defn)))
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)
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()
def execute_proc(args, fail0): if TRACE_APPLICATIONS: display(cons(symbol("<primitive>"), args)) print() return continue_with(succeed, apply_primitive_procedure(procedure, args), fail0)
def execute_proc(args, fail0): if TRACE_APPLICATIONS: display(cons(symbol("<continuation>"), args)) print() return continue_with(continuation.succeed, *args, continuation.fail)