| 1 |
\ifx\LOOP\relax\endinput\else\let\LOOP=\relax\fi % \input only once |
| 2 |
% |
| 3 |
% loop.tex: A simple looping construct (meta-macros). |
| 4 |
% version: 1.0 release: 26 June 1991 |
| 5 |
% |
| 6 |
% copyright (c) 1991 Marcel R. van der Goot |
| 7 |
% You can use these macros to typeset documents. You may |
| 8 |
% distribute this file freely, provided that you also distribute |
| 9 |
% the accompanying documentation. |
| 10 |
% You may make changes to this file, or extract portions |
| 11 |
% of it for inclusion in other files, provided that |
| 12 |
% (1) you change the name of the file; |
| 13 |
% (2) you give proper credit and include copyright |
| 14 |
% information where applicable; |
| 15 |
% (3) explain how an unchanged version can be obtained; and |
| 16 |
% (4) document the usage of your macros/changes (if usage |
| 17 |
% of your macros is not worth documenting, they must not |
| 18 |
% be worth using). |
| 19 |
% You are not allowed to use the name ``Midnight Macros'' for |
| 20 |
% any changed files. |
| 21 |
% The above rules for making changes do not apply where it |
| 22 |
% is explicitly noted in this file that something can be changed |
| 23 |
% to conform to your local installation. |
| 24 |
% |
| 25 |
% USAGE: |
| 26 |
% See the file loop.doc |
| 27 |
% |
| 28 |
% original: csvax.cs.caltech.edu [131.215.131.131] in pub/tex |
| 29 |
% (use anonymous ftp). Also in various archives. |
| 30 |
% |
| 31 |
% Caltech, Pasadena --- Marcel van der Goot |
| 32 |
% [email protected] |
| 33 |
% Caltech 256--80 |
| 34 |
% Pasadena, CA 91125 |
| 35 |
% USA |
| 36 |
% (818) 356--4603 |
| 37 |
% |
| 38 |
|
| 39 |
% update history: |
| 40 |
% version 1.0: This one. |
| 41 |
% release 26 April 1991: This one. |
| 42 |
% release 15 April 1991: Did not have \long in \Loop, \_break, and |
| 43 |
% \_continue. |
| 44 |
% release 8 Feb 1991: Used \next instead of \Lp_next. |
| 45 |
% |
| 46 |
|
| 47 |
%%%%%% CODE: (you don't need to read this to use the macros) |
| 48 |
|
| 49 |
{ |
| 50 |
\catcode`\_=11 % 11 = letter; to make macros private |
| 51 |
\globaldefs=1 |
| 52 |
|
| 53 |
% Code to supply \fi's: |
| 54 |
|
| 55 |
\def\do_fi{\fi\finish_ifs} |
| 56 |
|
| 57 |
\def\finish_ifs |
| 58 |
{\ifnum\count255>0 % |
| 59 |
\let\Lp_next=\do_fi |
| 60 |
\else\let\Lp_next=\relax |
| 61 |
\fi |
| 62 |
\advance\count255 by-1 % |
| 63 |
\Lp_next |
| 64 |
} |
| 65 |
|
| 66 |
% The loop (tail-recursion does not clog memory): |
| 67 |
|
| 68 |
\long\def\Loop#1\Pool% |
| 69 |
{\def\Pool{#1\Pool}% |
| 70 |
\Pool |
| 71 |
} |
| 72 |
|
| 73 |
% \Break could have been defined as |
| 74 |
% \def\Break#1#2\Pool{{\count255=#1 \finish_ifs}} |
| 75 |
% but this fails if you do |
| 76 |
% \ifnum\count0>5\Break |
| 77 |
% without space after the 5: \Break wil be expanded to see if there |
| 78 |
% are more digits (and expanding \Break means reading its 2nd argument). |
| 79 |
% With the solution below, only \Break is expanded because it starts |
| 80 |
% with \relax which is not a number. Using \afterassignment rather |
| 81 |
% than passing the number as argument gives better error messages. |
| 82 |
|
| 83 |
\def\Break |
| 84 |
{\relax\afterassignment\_break |
| 85 |
\bgroup\count255= |
| 86 |
} |
| 87 |
|
| 88 |
\long\def\_break#1\Pool% |
| 89 |
{\finish_ifs |
| 90 |
\egroup |
| 91 |
} |
| 92 |
|
| 93 |
\def\Continue |
| 94 |
{\relax\afterassignment\_continue |
| 95 |
\bgroup\count255= |
| 96 |
} |
| 97 |
|
| 98 |
\long\def\_continue#1\Pool% |
| 99 |
{\finish_ifs |
| 100 |
\egroup |
| 101 |
\Pool |
| 102 |
} |
| 103 |
|
| 104 |
} % restore \catcode`\_, \globaldefs |
| 105 |
|