def get(self, symbol: mytypes.MalSymbol): print(symbol, self.find(symbol)) env = self.find(symbol) if env is None: return mytypes.MalNil() for item in env.data.keys(): if item.content == symbol.content: return env.data[item]
def read_atom(reader:Reader): token = reader.next() print(token) if token.isnumeric(): return mytypes.MalNumber(float(token)) elif token[0] == "\"": return mytypes.MalString(read_str_(token)) elif token[0] == ":": return mytypes.MalKeyword(token[1:]) elif token == "true": return mytypes.MalBool(True) elif token == "false": return mytypes.MalBool(False) elif token == "nil": return mytypes.MalNil() else: return mytypes.MalSymbol(token)
def fn_deref(a): if a.my_type != "atom": return mytypes.MalNil() return a.content
def fn_print(a): print("OUTPUT: " + printer.print_str(a)) return mytypes.MalNil()
def EVAL(ast, _env: env.Env): '''Evaluates its input (tokens, probably)''' print("Ca") # print("LLLLLLLLLLLLLLLLLLLLLLLLLLL :::: !!!!!!! ;;;; :" + str(ast.content[1].content)) print(ast.my_type, _env) print(str(ast.content) + " MEMES") print("THE ASSYMETRICAL SYNTAX TABLE::::: !!!! " + str(ast.content)) if ast.my_type not in ["list", "vector"]: print("non list, breaking out") return eval_ast(ast, _env) try: a0 = ast.content[0] except IndexError: return mytypes.MalList([]) try: a1 = ast.content[1] except IndexError: a1 = mytypes.MalNil() try: a2 = ast.content[2] except IndexError: a2 = mytypes.MalNil() print("LARGE EGG " + str(a0)) if callable(a0): return a0(*ast.content[1:]) ast = macroexpand(ast, _env) if a0.my_type == "symbol": if "def!" == a0.content: print("^^^^^^^" + str(a1) + str(a2)) res = EVAL(a2, _env) return _env.set_(a1, res) elif "defmacro!" == a0.content: print("^^^^^^^" + str(a1) + str(a2)) res = EVAL(a2, _env) res.is_macro = True return _env.set_(a1, res) elif "let*" == a0.content: new_env = env.Env(ENV) a1, a2 = ast.content[1], ast.content[2] for i in range(0, len(a1.content), 2): new_env.set_(a1.content[i], EVAL(a1.content[i + 1], new_env)) return EVAL(a2, new_env) elif "do" == a0.content: a1 = ast.content[1] for item in a1.content: last = eval_ast(item, _env) return last elif "if" == a0.content: try: a3 = ast.content[3] except IndexError: a3 = None if EVAL(a1, _env).content: print("IT WAS TRUUEE!!!!") return EVAL(a2, _env) else: print("FALSEEE! NOT TRUEEE!!") if a3 != None: return EVAL(a3, _env) else: return mytypes.MalNil() elif "fn*" == a0.content: return mytypes.MalFuntion(EVAL, env.Env, a2, _env, a1) elif "quote" == a0.content: return a1 elif "quasiquote" == a0.content: return EVAL(quasiquote(ast.content[1]), _env) elif "macroexpand" == a0.content: return macroexpand(a1, _env) else: if not ast.content: return ast else: evaled = eval_ast(ast, _env) print("Evaluated Object " + str(evaled)) print("Evaluated Content " + str(evaled.content)) return evaled.content[0](*evaled.content[1:])