# Buggy code
def __init__(self, spy=False, output_fn=None, locals=None, filename="<input>"):
    super(HyREPL, self).__init__(locals=locals, filename=filename)

    # Create a proper module for this REPL so that we can obtain it easily
    # (e.g. using `importlib.import_module`).
    # Also, make sure it's properly introduced to `sys.modules` and
    # consistently use its namespace as `locals` from here on.
    module_name = self.locals.get("__name__", "__console__")
    self.module = sys.modules.setdefault(module_name, types.ModuleType(module_name))
    self.module.__dict__.update(self.locals)
    self.locals = self.module.__dict__

    # Load cmdline-specific macros.
    require("hy.cmdline", module_name, assignments="ALL")

    self.hy_compiler = HyASTCompiler(self.module)

    self.spy = spy

    if output_fn is None:
        self.output_fn = repr
    elif callable(output_fn):
        self.output_fn = output_fn
    else:
        if "." in output_fn:
            parts = [mangle(x) for x in output_fn.split(".")]
            module, f = ".".join(parts[:-1]), parts[-1]
            self.output_fn = getattr(importlib.import_module(module), f)
        else:
            self.output_fn = __builtins__[mangle(output_fn)]

    # Pre-mangle symbols for repl recent results: *1, *2, *3
    self._repl_results_symbols = [mangle("*{}".format(i + 1)) for i in range(3)]
    self.locals.update({sym: None for sym in self._repl_results_symbols})


# Traceback (hy.errors.HyCompileError)
Traceback (most recent call last):
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/importer.py", line 180, in hy_eval
_ast, expr = hy_compile(hytree, module_name, get_expr=True)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 2213, in hy_compile
result = compiler.compile(tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 819, in compile_do
return self._compile_branch(expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in _compile_branch
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 318, in _branch
results = list(results)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in <genexpr>
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 372, in checker
return fn(self, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 873, in compile_try_expression
name)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1002, in _compile_catch_expression
body = self._compile_branch(expr)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in _compile_branch
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 318, in _branch
results = list(results)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 545, in <genexpr>
return _branch(self.compile(expr) for expr in exprs)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 372, in checker
return fn(self, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 858, in compile_try_expression
body += self.compile(expr.pop(0))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 472, in compile
raise_empty(HyCompileError, e, sys.exc_info()[2])
File "<string>", line 1, in raise_empty
hy.errors.HyCompileError: Internal Compiler Bug 😱
⤷ ImportError: cannot require names: [HySymbol('let')]
Compilation traceback:
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 460, in compile
ret = self.compile_atom(_type, tree)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1731, in compile_expression
ret = self.compile_atom(fn, expression)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 447, in compile_atom
else _compile_table[atom_type](self, atom))
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/compiler.py", line 1486, in compile_require
require(module, self.module_name, assignments=assignments)
File "/home/johnzhuang/.virtualenvs/hy/lib/python3.6/site-packages/hy/macros.py", line 106, in require
raise ImportError("cannot require names: " + repr(list(unseen)))

# Fixed code
def __init__(self, spy=False, output_fn=None, locals=None, filename="<stdin>"):
    # Create a proper module for this REPL so that we can obtain it easily
    # (e.g. using `importlib.import_module`).
    # We let `InteractiveConsole` initialize `self.locals` when it's
    # `None`.
    super(HyREPL, self).__init__(locals=locals, filename=filename)

    module_name = self.locals.get("__name__", "__console__")
    # Make sure our newly created module is properly introduced to
    # `sys.modules`, and consistently use its namespace as `self.locals`
    # from here on.
    self.module = sys.modules.setdefault(module_name, types.ModuleType(module_name))
    self.module.__dict__.update(self.locals)
    self.locals = self.module.__dict__

    # Load cmdline-specific macros.
    require("hy.cmdline", self.module, assignments="ALL")

    self.hy_compiler = HyASTCompiler(self.module)

    self.compile = HyCommandCompiler(self.module, self.ast_callback, self.hy_compiler)

    self.spy = spy
    self.last_value = None

    if output_fn is None:
        self.output_fn = repr
    elif callable(output_fn):
        self.output_fn = output_fn
    else:
        if "." in output_fn:
            parts = [mangle(x) for x in output_fn.split(".")]
            module, f = ".".join(parts[:-1]), parts[-1]
            self.output_fn = getattr(importlib.import_module(module), f)
        else:
            self.output_fn = __builtins__[mangle(output_fn)]

    # Pre-mangle symbols for repl recent results: *1, *2, *3
    self._repl_results_symbols = [mangle("*{}".format(i + 1)) for i in range(3)]
    self.locals.update({sym: None for sym in self._repl_results_symbols})