I recommend using functions. Functions are more powerful than macros or @generated
functions for solving problems like this. See tail-call function-barrier pattern I discussed in
- State machines · Transducers.jl
- Tail-call optimization and function-barrier -based accumulation in loops
(At some previous versions of Transducers.jl, you could just write a simple loop FLoops.jl and the accumulator automatically converged to the fixpoint. But it is an opt-in feature ATM for “prelude” accumulator to reduce compile overhead.)
A generalized version of this is used in