Wrapping for loops in Pyteal

I want to wrap for loops in PyTeal for readability purposes. I want to pass the scratch_var as an argument to the for_loop_wrapper function. I am getting an error in PyTeal:

Argument at index 0 of subroutine call is not a PyTeal expression: <pyteal.ScratchVar object at 0x7ff5089dddc0>

Below is the my code:

    @Subroutine(TealType.none)
    def for_loop_wrapper(scratch_var, start: TealType.uint64, stopping_condition: TealType.uint64, increment: TealType.uint64):
        return Seq([

                For(scratch_var.store(start), scratch_var.load() < stopping_condition, scratch_var.store(scratch_var.load() + increment)).Do(Seq([
                    Log(Itob(scratch_var.load())),
                ])),

                Return()
            ])

    @Subroutine(TealType.none)
    def for_loop():
        scratch_var = ScratchVar(TealType.uint64)
        return Seq([

                for_loop(scratch_var, Int(0), Int(20), Int(1)),

                Return()
            ])

Any thoughts on this?

Javier

you can’t pass the scratch var as an argument to the subroutine.

It doesn’t look like you’re actually using it in the caller, why not declare it inside the for_loop_wrapper ?

Got it. If I were to pass a subroutine to the for_loop_wrapper, what type would I label it as? I also want to pass in the logic for every iteration of the for loop.

EDIT: So I have been trying some stuff out, and it seems like PyTeal currently does not allow passing in subroutines to other subroutines. Is this correct? Only recursion of the same subroutine is allowed.