Hopefully these answer your questions:
Why are these two lines needed before the definition of “substitute_args”?
They are different methods of the same function: Methods · The Julia Language
This is a fundamentally cool feature of Julia, so it’s worth learning in detail.
How can the function “substitute_args” be called within the definition of “substitute_args”?
Most programming languages allow this. See, e.g., Recursion (computer science) - Wikipedia