How to define a recursive custom function using autograd.Function in a elegant way?

I am a new user to PyTorch, after reading the PyTorch Documentation Extending PyTorch, I am thinking about writing a recursive custom function. As in the example code, when writing staticmethod part ‘forward’:

It seems that directly calling ‘forward’ function in ‘return’ line gives an error.

So I am wondering about How to define a recursive custom function using autograd.Function in a elegant way?

Thanks a lot for your answer and help!