src/basilisp/lang/compiler/generator.py
def _let_to_py_ast(ctx: GeneratorContext, node: Let) -> GeneratedPyAST:
    """Return a Python AST Node for a `let*` expression."""
    assert node.op == NodeOp.LET

    with ctx.new_symbol_table("let"):
        let_body_ast: List[ast.AST] = []
        for binding in node.bindings:
            init_node = binding.init
            assert init_node is not None
            init_ast = gen_py_ast(ctx, init_node)
            binding_name = genname(munge(binding.name))
            let_body_ast.extend(init_ast.dependencies)
            let_body_ast.append(
                ast.Assign(
                    targets=[ast.Name(id=binding_name, ctx=ast.Store())],
                    value=init_ast.node,
                )
            )
            ctx.symbol_table.new_symbol(
                sym.symbol(binding.name), binding_name, LocalType.LET
            )

        let_result_name = genname("let_result")
        body_ast = _synthetic_do_to_py_ast(ctx, node.body)
        let_body_ast.extend(map(statementize, body_ast.dependencies))
        let_body_ast.append(
            ast.Assign(
                targets=[ast.Name(id=let_result_name, ctx=ast.Store())],
                value=body_ast.node,
            )
        )

        return GeneratedPyAST(
            node=ast.Name(id=let_result_name, ctx=ast.Load()), dependencies=let_body_ast
        )
def _let_to_py_ast(ctx: GeneratorContext, node: Let) -> GeneratedPyAST:
    """Return a Python AST Node for a `let*` expression."""
    assert node.op == NodeOp.LET

    with ctx.new_symbol_table("let"):
        let_body_ast: List[ast.AST] = []
        for binding in node.bindings:
            init_node = binding.init
            assert init_node is not None
            init_ast = gen_py_ast(ctx, init_node)
            binding_name = genname(munge(binding.name))
            let_body_ast.extend(init_ast.dependencies)
            let_body_ast.append(
                ast.Assign(
                    targets=[ast.Name(id=binding_name, ctx=ast.Store())],
                    value=init_ast.node,
                )
            )
            ctx.symbol_table.new_symbol(
                sym.symbol(binding.name), binding_name, LocalType.LET
            )

        let_result_name = genname("let_result")
        body_ast = _synthetic_do_to_py_ast(ctx, node.body)
        let_body_ast.extend(map(statementize, body_ast.dependencies))
        let_body_ast.append(
            ast.Assign(
                targets=[ast.Name(id=let_result_name, ctx=ast.Store())],
                value=body_ast.node,
            )
        )

        return GeneratedPyAST(
            node=ast.Name(id=let_result_name, ctx=ast.Load()), dependencies=let_body_ast
        )
def _let_to_py_ast ( ctx : GeneratorContext , node : Let ) -> GeneratedPyAST : assert node . op == NodeOp . LET with ctx . new_symbol_table ( "let" ) : let_body_ast : List [ ast . AST ] = [ ] for binding in node . bindings : init_node = binding . init assert init_node is not None init_ast = gen_py_ast ( ctx , init_node ) binding_name = genname ( munge ( binding . name ) ) let_body_ast . extend ( init_ast . dependencies ) let_body_ast . append ( ast . Assign ( targets = [ ast . Name ( id = binding_name , ctx = ast . Store ( ) ) ] , value = init_ast . node , ) ) ctx . symbol_table . new_symbol ( sym . symbol ( binding . name ) , binding_name , LocalType . LET ) let_result_name = genname ( "let_result" ) body_ast = _synthetic_do_to_py_ast ( ctx , node . body ) let_body_ast . extend ( map ( statementize , body_ast . dependencies ) ) let_body_ast . append ( ast . Assign ( targets = [ ast . Name ( id = let_result_name , ctx = ast . Store ( ) ) ] , value = body_ast . node , ) ) return GeneratedPyAST ( node = ast . Name ( id = let_result_name , ctx = ast . Load ( ) ) , dependencies = let_body_ast )
Return a Python AST Node for a `let*` expression.
Return a Python AST Node for a let * expression .