def if_alternative(exp): if is_null(cdddr(exp)): return Symbol("the-unspecified-value") else: return cadddr(exp)
def make_begin(actions): return cons(Symbol("begin"), actions)
def is_if(exp): return is_tagged_list(exp, Symbol("if"))
def make_lambda(parameters, body): return cons( Symbol("lambda"), cons(parameters, begin_actions(body) if is_begin(body) else (body, )), )
def is_begin(exp): return is_tagged_list(exp, Symbol("begin"))
def is_definition(exp): return is_tagged_list(exp, Symbol("define"))
def is_lambda(exp): return is_tagged_list(exp, Symbol("lambda"))
def is_assignment(exp): return is_tagged_list(exp, Symbol("set!"))
def is_undoable_assignment(exp): return is_tagged_list(exp, Symbol("maybe-set!"))
def make_if(pred, conseq, alternative): return Symbol("if"), pred, conseq, alternative
def is_cond(exp): return is_tagged_list(exp, Symbol("cond"))
def is_let(exp): return is_tagged_list(exp, Symbol("let"))
def is_else_clause(clause): return cond_clause_predicate(clause) == Symbol("else")
THE_GLOBAL_ENVIRONMENT = "not initialized" 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), ()))