I have defined a stack structure (I found an example in the LaTeX currfile package, which I adapted to my needs):
\def\MB@modulestack{}
\def\MB@modulestack@push#1{\xdef\MB@modulestack{{#1}\MB@modulestack}}
\def\MB@modulestack@top{\expandafter\MB@modulestack@top@eat\MB@modulestack\relax\relax}
\def\MB@modulestack@top@eat#1#2\relax{#1}
\def\MB@modulestack@pop{\expandafter\MB@modulestack@pop@eat\MB@modulestack\relax\relax}
\def\MB@modulestack@pop@eat#1#2\relax{\gdef\MB@modulestack{#2}}
I understand how it works, especially those \relax. I keep a 4-tuple of parameters there:
\def\MB@modulestack@push{{a}{b}{c}{d}}
\def\MB@modulestack@push{{1}{2}{3}{4}}
Now, to parse such a 4-tuple from the top of stack I wanted to use the following code:
\def\MB@modulestack@topitemparse@eat#1#2#3#4{... here I use #1, #2, #3, #4 ...}
\def\MB@modulestack@topitemparse{
\expandafter\MB@modulestack@topitemparse@eat\MB@modulestack@top
}
...but it didn't work. While experimenting I found that I had to do this another way:
\def\MB@modulestack@topitemparse@eat#1#2#3#4#5\relax{... here I use #1, #2, #3, #4 ...}
\def\MB@modulestack@topitemparse{
\edef\MB@modulestack@topitem{\MB@modulestack@top}
\expandafter\MB@modulestack@topitemparse@eat\MB@modulestack@topitem\relax\relax
}
Why does the first doesn't work and the second does? Why do I need to get #5 and \relax in the @eat macro? Why do I need to read the top of stack into variable, instead of passing it straight to the @eat macro?