For now, I'll answer only your second question, about the example from e-TeX. The \expandafter are used to force TeX to actually do the computation before calling \foo recursively, and to clear the finale \fi so that the recursion is terminal. This isn't strictly necessary but is an optimisation. Here is a way to visually check my first assertion:
\documentclass{minimal} \def\foo#1#2{\noindent\number#1 \ifnum#1<#2, \expandafter\foo \expandafter{\number\numexpr#1+1\expandafter}% \expandafter{\number#2\expandafter}% \fi} \def\noexpfoo#1#2{\noindent\number#1 \ifnum#1<#2, \noexpfoo {\number\numexpr#1+1}% {\number#2}% \fi} \begin{document} \tracingmacros1 \foo{1}{5} \noexpfoo{1}{5} \tracingmacros0 \end{document}
After compiling this file, look at the log. You can check that the last call of \foo has arguments 5 and 5, while the last call to \noexpfoo has \number \numexpr \number \numexpr \number \numexpr \number \numexpr 1+1+1+1+1 as its first argument, which is essentially a representation of 5 in base one, as opposed to its base ten representation used in the \expandafter case. The size of the first argument grows exponentially in the no-expandafter case. This is very bad and will make TeX crash due to lack of memory, or at least run very slowly, for big loops.
Clearing the final \fi serves the same purpose of making the macro more scalable, in a different way. Without the final \expandafter in the definition of \foo, at the final call, TeX's input stack would look like \foo{5}{5}\fi\fi\fi\fi\fi, with all the associated information about with macro call the different \fi are coming from. With the final \expandafter (indirectly triggered by the first one), the input stack looks like \foo{5}{5} without any trailing \if.
I'm not including more details about \expandafter chaining and the way conditionals expand to keep the answer focused, but feel free to ask if needed.
Also, the comma is after the \ifnum test so that you get 1, 2, 3, 4, 5 without a trailing comma-space as in 1, 2, 3, 4, 5,.
Complement about expansion. So, in the definition of \foo there are 5 \expandafters and three \numbers. The first \expandafter expands whatever there is after \foo, which happens to be the second \expandafter, which in turns expands what follows the brace, ie the second \number (the first one is earlier in the macro). Now, \number tries to read a number expanding everything until it finds something that doesn't belong to a number. Here the right brace will stop that process, but it won't be hit until the third \expandafter is expanded, which triggers the fourth \expandafter, which in turn triggers the last \number which, in the course of processing everything up to the closing brace, triggers the next \expandafter, which expands whatever comes after the brace, which is... wait for it... \fi.
Now, a common misconception about how TeX handles (expands) conditionals is to forget that the \fi is still here. When TeX expands the \ifnum, it doesn't read everything up to the \fi. That's what a macro would do with its arguments: read them entirely. But branches of conditionals are not macro arguments. Instead, when expanding \ifnum and seeing it is true, TeX just continues reading the rest, making a note to self that the next \fi encountered is completely normal and should be silently expanding to nothing. If it encounters a \else first, then is will ignore it and everything up to (and including) the closing \fi. So, only ignored branches are treated as a block.
\fooa,\foobetc would be okay) to the different version of\foo, so that it's easier to refer to them? Including a name for "the second version of\foowith\else\relaxuncommented", please :-) Also, I'm not sure I understand: do you expect the second version of\footo give the same result as the first one?