summaryrefslogtreecommitdiff
path: root/info/examples/tip/list-mac.tip
blob: b8c1f6d72eb70dd1b3f128fa49b533833a88879b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
% This macro source file is from the four volume series
% "TeX in Practice" by Stephan von Bechtolsheim, published
% 1993 by Springer-Verlag, New York.
% Copyright 1993 Stephan von Bechtolsheim.
% No warranty or liability is assumed.
% This macro may be copied freely if no fees other than
% media cost or shipping charges are charged and as long
% as this copyright and the following source code itself
% is not changed. Please see the series for further information.
%
% Version: 1.0
% Date: May 1, 1993
%
%
% This source code is documented in 20.2.2, p. III-121.
% Original source in file "tokens3.TEX", starting line 263.
\wlog{L: "list-mac.tip" ["tokens3.TEX," l. 263, p. III-121]}%
% This file DOES belong to format "texip."
\InputD{compst.tip}
\catcode`\@ = 11
\def\@EmptyRefList{}
\def\EmptyListConditional #1{%
    TT\fi
    \ifx#1\@EmptyRefList
}
\newtoks\@AppendTokOne
\newtoks\@AppendTokTwo
\def\LeftAppendElement #1#2{%
    \edef\@AppendTemp{\noexpand\\{#2}}% 
    \@AppendTokOne = \expandafter{\@AppendTemp}%
    \@AppendTokTwo = \expandafter{#1}%
    \edef#1{\the\@AppendTokOne \the\@AppendTokTwo}%
}
\def\RightAppendElement #1#2{%
    \edef\@AppendTemp{\noexpand\\{#2}}% 
    \@AppendTokOne = \expandafter{\@AppendTemp}%
    \@AppendTokTwo = \expandafter{#1}%
    \edef#1{\the\@AppendTokTwo \the\@AppendTokOne}%
}
\def\CarOfList #1#2{%
    \def\@CarTemp \\##1##2\@EndCarList{\def#2{##1}}%
    \expandafter\@CarTemp#1\@EndCarList
}
\def\CdrOfList #1#2{% 
    \def\@CdrTemp \\##1##2\@EndCdrList{\def#2{##2}}% 
    \expandafter\@CdrTemp#1\@EndCdrList
}
\def\DropFirstElementOfList #1{% 
    \if\EmptyListConditional{#1}% 
        \errhelp = {\string\DropFirstElementOfList: list is
            empty. No first element to drop.}%
        \errmessage{\string\DropFirstElementOfList: List
            \noexpand#1 is empty.}%
    \else
        \def\@DropFirstElementTemp \\##1##2\@EndCdrList{\def#1{##2}}%
        \expandafter\@DropFirstElementTemp#1\@EndCdrList
    \fi
}
\def\CarCarOfList #1#2{%
    \let\@CarCarOfListList = #1%
    \DropFirstElementOfList{\@CarCarOfListList}%
    \CarOfList{\@CarCarOfListList}{#2}
}
\def\ForEveryListElement #1#2{%
    \let\@ForEveryList = #1%
    \let\@ForEveryListElementMacro = #2%
    \@ForEveryListElement
}
\def\@ForEveryListElement{%
    \if\EmptyListConditional{\@ForEveryList}%
        \let\@ForEveryListElementNext = \relax
    \else
        \CarOfList{\@ForEveryList}{\@ForEveryListElementElement}%
        \@ForEveryListElementMacro{\@ForEveryListElementElement}%
        \DropFirstElementOfList{\@ForEveryList}%
        \let\@ForEveryListElementNext = \@ForEveryListElement
    \fi
    \@ForEveryListElementNext
}
\newif\if@MemberList
\def\MemberOfListConditional #1#2{%
    TT\fi
    \@MemberListfalse
    {%
        \def\\##1{% 
            \if\StringsEqualConditional{#2}{##1}% 
                \global\@MemberListtrue
            \fi
        }%
        #1% 
    }%
    \if@MemberList
}
\def\ReverseList #1#2{%
    \def\@ReverseListOut{}%
    \ForEveryListElement{#1}{\@ReverseList}%
    \let#2 = \@ReverseListOut
}
\def\@ReverseList #1{% 
    \LeftAppendElement{\@ReverseListOut}{#1}%
}
\def\LastElementOfList #1#2{%
    \ReverseList{#1}{#1}%
    \CarOfList{#1}{#2}%
    \ReverseList{#1}{#1}%
}
\def\DropLastElementOfList #1{%
    \ReverseList{#1}{#1}%
    \DropFirstElementOfList{#1}%
    \ReverseList{#1}{#1}%
}
\def\NumberOfListElements #1#2{% 
    \let\@NumberOfListElementsList = #1%
    \def\@NumberOfListElementsCount{#2}%
    \@NumberOfListElementsCount = 0
    \@NumberOfListElements  
}
\def\@NumberOfListElements{%
    \if\EmptyListConditional{\@NumberOfListElementsList}%
        \let\@NumberOfListElementsNext = \relax
    \else
        \advance\@NumberOfListElementsCount by 1
        \DropFirstElementOfList{\@NumberOfListElementsList}%
        \let\@NumberOfListElementsNext = \@NumberOfListElements
    \fi
    \@NumberOfListElementsNext
}
\newcount\@NumberOfListElCCount
\def\NumberOfListElementsNumConditional #1{%
    0=0\fi
    \NumberOfListElements{#1}{\@NumberOfListElCCount}%
    \ifnum\@NumberOfListElCCount
}
\def\CombineTwoLists #1#2#3{%
    \def\@CombineTwoLists{\def\@CombineTwoListsResult}%
    \expandafter\expandafter\expandafter
    \expandafter\expandafter\expandafter
    \expandafter\@CombineTwoLists
    \expandafter\expandafter\expandafter{\expandafter#1#2}%
    \let #3 = \@CombineTwoListsResult
}
\catcode`\@ = 12