blob: fad727278daad197e0a595832e56317f659cd2be (
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
|
%%
%% This is file `l3prg.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% l3prg.dtx (with options: `package')
%%
%%
%% EXPERIMENTAL CODE
%%
%% Do not distribute this file without also distributing the
%% source files specified above.
%%
%% Do not distribute a modified version of this file.
%%
%%
%% File: l3prg.dtx Copyright (C) 2005-2006 LaTeX3 project
%%
%% It may be distributed and/or modified under the conditions of the
%% LaTeX Project Public License (LPPL), either version 1.3c of this
%% license or (at your option) any later version. The latest version
%% of this license is in the file
%%
%% http://www.latex-project.org/lppl.txt
%%
%% This file is part of the ``expl3 bundle'' (The Work in LPPL)
%% and all files in that bundle must be distributed together.
%%
%% The released version of this bundle is available from CTAN.
%%
%% -----------------------------------------------------------------------
%%
%% The development version of the bundle can be found at
%%
%% http://www.latex-project.org/cgi-bin/cvsweb.cgi/
%%
%% for those people who are interested.
%%
%%%%%%%%%%%
%% NOTE: %%
%%%%%%%%%%%
%%
%% Snapshots taken from the repository represent work in progress and may
%% not work or may contain conflicting material! We therefore ask
%% people _not_ to put them into distributions, archives, etc. without
%% prior consultation with the LaTeX Project Team.
%%
%% -----------------------------------------------------------------------
\RequirePackage{l3names}
\GetIdInfo$Id: l3prg.dtx 574 2006-08-21 23:30:10Z morten $
{L3 Experimental control structures}
\RequirePackage{l3quark}
\RequirePackage{l3toks}
\RequirePackage{l3int}
\def_new:Npn \mode_vertical_p: {
\if_mode_vertical: \c_true \else: \c_false\fi:}
\def_test_function_new:npn{mode_vertical:}{\if_mode_vertical:}
\def_new:Npn \mode_horizontal_p: {
\if_mode_horizontal: \c_true \else: \c_false\fi:}
\def_test_function_new:npn{mode_horizontal:}{\if_mode_horizontal:}
\def_new:Npn \mode_inner_p: {
\if_mode_inner: \c_true \else: \c_false\fi:}
\def_test_function_new:npn{mode_inner:}{\if_mode_inner:}
\def_test_function_new:npn{mode_math:} {
\scan_align_safe_stop: \if_mode_math: }
\def_new:Npn \group_align_safe_begin: {\if_false:{\fi:\if_num:w0=`}\fi:}
\def_new:Npn \group_align_safe_end: {\if_num:w0=`{\fi:\if_false:}\fi:}
\def_new:Npn \scan_align_safe_stop: {
\num_compare:nNnT \etex_currentgrouptype:D = \c_six
{
\num_compare:nNnF \etex_lastnodetype:D = \c_zero
{
\num_compare:nNnF \etex_lastnodetype:D = \c_seven
\scan_stop:
}
}
}
\def_new:Npn \prg_replicate:nn #1{
\cs:w use_noop:
\exp_after:NN\prg_replicate_first_aux:N
\int_use:N \int_eval:n{#1} \cs_end:
\cs_end:
}
\def_new:Npn \prg_replicate_aux:N#1{
\cs:w prg_replicate_#1:n\prg_replicate_aux:N
}
\def_new:Npn \prg_replicate_first_aux:N#1{
\cs:w prg_replicate_first_#1:n\prg_replicate_aux:N
}
\def_new:Npn \prg_replicate_ :n #1{}% no, this is not a typo!
\def_long_new:cpn {prg_replicate_0:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}}
\def_long_new:cpn {prg_replicate_1:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1}
\def_long_new:cpn {prg_replicate_2:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1}
\def_long_new:cpn {prg_replicate_3:n}#1{
\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1}
\def_long_new:cpn {prg_replicate_4:n}#1{
\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1}
\def_long_new:cpn {prg_replicate_5:n}#1{
\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_6:n}#1{
\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_7:n}#1{
\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_8:n}#1{
\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_9:n}#1{
\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_first_0:n}#1{\cs_end: }
\def_long_new:cpn {prg_replicate_first_1:n}#1{\cs_end: #1}
\def_long_new:cpn {prg_replicate_first_2:n}#1{\cs_end: #1#1}
\def_long_new:cpn {prg_replicate_first_3:n}#1{\cs_end: #1#1#1}
\def_long_new:cpn {prg_replicate_first_4:n}#1{\cs_end: #1#1#1#1}
\def_long_new:cpn {prg_replicate_first_5:n}#1{\cs_end: #1#1#1#1#1}
\def_long_new:cpn {prg_replicate_first_6:n}#1{\cs_end: #1#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_first_7:n}#1{\cs_end: #1#1#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_first_8:n}#1{\cs_end: #1#1#1#1#1#1#1#1}
\def_long_new:cpn {prg_replicate_first_9:n}#1{\cs_end: #1#1#1#1#1#1#1#1#1}
\def_long_new:NNn \prg_stepwise_function:nnnN 2{
\num_compare:nNnTF{#2}<\c_zero
{\exp_args:No\prg_stepwise_function_decr:nnnN }
{\exp_args:No\prg_stepwise_function_incr:nnnN }
{\int_use:N\int_eval:n{#1}}{#2}
}
\def_long_new:NNn \prg_stepwise_function_incr:nnnN 4{
\num_compare:nNnF {#1}>{#3}
{
#4{#1}
\exp_args:No \prg_stepwise_function_incr:nnnN
{\int_use:N\int_eval:n{#1 + #2}}
{#2}{#3}{#4}
}
}
\def_long_new:NNn \prg_stepwise_function_decr:nnnN 4{
\num_compare:nNnF {#1}<{#3}
{
#4{#1}
\exp_args:No \prg_stepwise_function_decr:nnnN
{\int_use:N\int_eval:n{#1 + #2}}
{#2}{#3}{#4}
}
}
\int_new:N\l_prg_inline_level_int
\def_long_new:NNn\prg_stepwise_inline:nnnn 4{
\int_incr:N \l_prg_inline_level_int
\def:cpn{prg_stepwise_inline_\int_use:N\l_prg_inline_level_int :n}##1{#4}
\num_compare:nNnTF {#2}<\c_zero
{\exp_args:Nco \prg_stepwise_inline_decr:Nnnn }
{\exp_args:Nco \prg_stepwise_inline_incr:Nnnn }
{prg_stepwise_inline_\int_use:N\l_prg_inline_level_int :n}
{\int_use:N\int_eval:n{#1}} {#2} {#3}
\int_decr:N \l_prg_inline_level_int
}
\def_long_new:NNn \prg_stepwise_inline_incr:Nnnn 4{
\num_compare:nNnF {#2}>{#4}
{
#1{#2}
\exp_args:NNo \prg_stepwise_inline_incr:Nnnn #1
{\int_use:N\int_eval:n{#2 + #3}} {#3}{#4}
}
}
\def_long_new:NNn \prg_stepwise_inline_decr:Nnnn 4{
\num_compare:nNnF {#2}<{#4}
{
#1{#2}
\exp_args:NNo \prg_stepwise_inline_decr:Nnnn #1
{\int_use:N\int_eval:n{#2 + #3}} {#3}{#4}
}
}
\def_long_new:NNn \prg_stepwise_variable:nnnNn 2 {
\num_compare:nNnTF {#2}<\c_zero
{\exp_args:No\prg_stepwise_variable_decr:nnnNn}
{\exp_args:No\prg_stepwise_variable_incr:nnnNn}
{\int_use:N\int_eval:n{#1}}{#2}
}
\def_long_new:NNn \prg_stepwise_variable_incr:nnnNn 5 {
\num_compare:nNnF {#1}>{#3}
{
\def:Npn #4{#1} #5
\exp_args:No \prg_stepwise_variable_incr:nnnNn
{\int_use:N\int_eval:n{#1 + #2}}{#2}{#3}#4{#5}
}
}
\def_long_new:NNn \prg_stepwise_variable_decr:nnnNn 5 {
\num_compare:nNnF {#1}<{#3}
{
\def:Npn #4{#1} #5
\exp_args:No \prg_stepwise_variable_decr:nnnNn
{\int_use:N\int_eval:n{#1 + #2}}{#2}{#3}#4{#5}
}
}
\def_new:Npn \bool_new:N #1 { \let_new:NN #1 \c_false }
\def_new:Npn \bool_new:c #1 { \let_new:cN #1 \c_false }
\def_new:Npn \bool_set_true:N #1 { \let:NN #1 \c_true }
\def_new:Npn \bool_set_true:c #1 { \let:cN #1 \c_true }
\def_new:Npn \bool_set_false:N #1 { \let:NN #1 \c_false }
\def_new:Npn \bool_set_false:c #1 { \let:cN #1 \c_false }
\def_new:Npn \bool_gset_true:N #1 { \glet:NN #1 \c_true }
\def_new:Npn \bool_gset_true:c #1 { \glet:cN #1 \c_true }
\def_new:Npn \bool_gset_false:N #1 { \glet:NN #1 \c_false }
\def_new:Npn \bool_gset_false:c #1 { \glet:cN #1 \c_false }
\let_new:NN \bool_set_eq:NN \let:NN
\let_new:NN \bool_set_eq:Nc \let:Nc
\let_new:NN \bool_set_eq:cN \let:cN
\let_new:NN \bool_set_eq:cc \let:cc
\let_new:NN \bool_gset_eq:NN \glet:NN
\let_new:NN \bool_gset_eq:Nc \glet:Nc
\let_new:NN \bool_gset_eq:cN \glet:cN
\let_new:NN \bool_gset_eq:cc \glet:cc
\bool_new:N \l_tmpa_bool
\bool_new:N \g_tmpa_bool
\def_test_function_new:npn{bool_if:N}#1{\if:w #1}
\def_new:Npn \bool_if:cTF{\exp_args:Nc\bool_if:NTF}
\def_new:Npn \bool_if:cT{\exp_args:Nc\bool_if:NT}
\def_new:Npn \bool_if:cF{\exp_args:Nc\bool_if:NF}
\def_new:Npn \bool_if_p:N #1 { #1 }
\let_new:NN \bool_if_p:c \cs_use:c
\def_long_new:Npn \bool_whiledo:NT #1 #2 {
\bool_if:NT #1 {#2 \bool_whiledo:NT #1 {#2}}
}
\def_new:Npn \bool_whiledo:cT{\exp_args:Nc\bool_whiledo:NT}
\def_long_new:Npn \bool_whiledo:NF #1 #2 {
\bool_if:NF #1 {#2 \bool_whiledo:NF #1 {#2}}
}
\def_new:Npn \bool_whiledo:cF{\exp_args:Nc\bool_whiledo:NF}
\def_long_new:Npn \bool_dowhile:NT #1 #2 {
#2 \bool_if:NT #1 {\bool_dowhile:NT #1 {#2}}
}
\def_new:Npn \bool_dowhile:cT{\exp_args:Nc\bool_dowhile:NT}
\def_long_new:Npn \bool_dowhile:NF #1 #2 {
#2 \bool_if:NF #1 {\bool_dowhile:NF #1 {#2}}
}
\def_new:Npn \bool_dowhiledo:cF{\exp_args:Nc\bool_dowhile:cF}
\def_new:Npn \bool_double_if:NNnnnn#1#2{
\if_case:w \num_eval:w #1\scan_stop:
\if_case:w \num_eval:w #2\scan_stop:
\exp_after:NN\exp_after:NN\exp_after:NN \use_arg_i:nnnn
\else:
\exp_after:NN\exp_after:NN\exp_after:NN \use_arg_ii:nnnn
\fi:
\else:
\if_case:w \num_eval:w #2\scan_stop:
\exp_after:NN\exp_after:NN\exp_after:NN \use_arg_iii:nnnn
\else:
\exp_after:NN\exp_after:NN\exp_after:NN \use_arg_iv:nnnn
\fi:
\fi:
}
\def_new:Npn \bool_double_if:cNnnnn{\exp_args:Nc\bool_double_if:NNnnnn}
\def_new:Npn \bool_double_if:Ncnnnn{\exp_args:NNc\bool_double_if:NNnnnn}
\def_new:Npn \bool_double_if:ccnnnn{\exp_args:Ncc\bool_double_if:NNnnnn}
\def_long_new:Npn \prg_whiledo:nT #1#2{
#1 {#2 \prg_whiledo:nT {#1}{#2}}
}
\def_long_new:Npn \prg_whiledo:nF #1#2{
#1 {#2 \prg_whiledo:nF {#1}{#2}}
}
\def_long_new:Npn \prg_dowhile:nT #1#2{
#2 #1 {\prg_dowhile:nT {#1}{#2}}
}
\def_long_new:Npn \prg_dowhile:nF #1#2{
#2 #1 {\prg_dowhile:nF {#1}{#2}}
}
\let_new:NN \prg_if_predicate:nTF \bool_if:NTF
\let_new:NN \prg_if_predicate:nT \bool_if:NT
\let_new:NN \prg_if_predicate:nF \bool_if:NF
\def_new:Npn \prg_if_predicate_or_p:nn #1#2{
\if_num:w #1#2<\c_hundred_one
\c_true
\else:
\c_false
\fi:
}
\def_new:Npn \prg_if_predicate_and_p:nn #1#2{
\if_case:w #1#2 ~
\c_true
\else:
\c_false
\fi:
}
\def_new:Npn \prg_if_predicate_not_p:n #1{
\if_case:w #1 ~
\c_false
\or:
\c_true
\fi:
}
\def_long_new:Npn \prg_if_predicate_ands_p:n #1{
\exp_after:NN \prg_if_predicate_andor_aux:NNN \exp_after:NN \c_true
\int_to_roman:w -`0 #1 \scan_stop: \scan_stop:
}
\def_long_new:Npn \prg_if_predicate_ors_p:n #1{
\exp_after:NN \prg_if_predicate_andor_aux:NNN \exp_after:NN \c_false
\int_to_roman:w -`0 #1 \scan_stop: \scan_stop:
}
\def_new:Npn \prg_if_predicate_andor_aux:NNN #1#2#3{
\token_if_eq_meaning:NNTF \scan_stop: #2
{ #1 }
{
\int_compare:nNnTF #3 = #1
{ \exp_after:NN \prg_if_predicate_andor_aux:NNN }
{ \exp_after:NN \prg_if_predicate_andor_break:NNN }
\exp_after:NN #1 \int_to_roman:w -`0
}
}
\def_new:Npn \prg_if_predicate_andor_break:NNN #1#2#3{
\token_if_eq_meaning:NNTF \scan_stop: #2
{ \if:w #1\c_false\else:\c_true\fi: }
{
\exp_after:NN \prg_if_predicate_andor_break:NNN \exp_after:NN #1
\int_to_roman:w -`0
}
}
\def_new:NNn \prg_define_quicksort:nnn 3 {
\def_long:cNx{#1_quicksort:n}1{
\exp_not:c{#1_quicksort_start_partition:w} ##1
\exp_not:n{#2\q_nil#3\q_stop}
}
\def_long:cNx{#1_quicksort_braced:n}1{
\exp_not:c{#1_quicksort_start_partition_braced:n} ##1
\exp_not:N\q_nil\exp_not:N\q_stop
}
\def_long:cpx {#1_quicksort_start_partition:w} #2 ##1 #3{
\exp_not:N \quark_if_nil:nT {##1}\exp_not:N \use_none_delimit_by_q_stop:w
\exp_not:c{#1_quicksort_do_partition_i:nnnw} {##1}{}{}
}
\def_long:cNx {#1_quicksort_start_partition_braced:n} 1 {
\exp_not:N \quark_if_nil:nT {##1}\exp_not:N \use_none_delimit_by_q_stop:w
\exp_not:c{#1_quicksort_do_partition_i_braced:nnnn} {##1}{}{}
}
\def_long:cpx {#1_quicksort_do_partition_i:nnnw} ##1##2##3 #2 ##4 #3 {
\exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw}
{
\exp_not:c{#1_quicksort_compare:nnTF}{##1}{##4}
\exp_not:c{#1_quicksort_partition_greater_ii:nnnn}
\exp_not:c{#1_quicksort_partition_less_ii:nnnn}
}
{##1}{##2}{##3}{##4}
}
\def_long:cNx {#1_quicksort_do_partition_i_braced:nnnn} 4 {
\exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw}
{
\exp_not:c{#1_quicksort_compare:nnTF}{##1}{##4}
\exp_not:c{#1_quicksort_partition_greater_ii_braced:nnnn}
\exp_not:c{#1_quicksort_partition_less_ii_braced:nnnn}
}
{##1}{##2}{##3}{##4}
}
\def_long:cpx {#1_quicksort_do_partition_ii:nnnw} ##1##2##3 #2 ##4 #3 {
\exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw}
{
\exp_not:c{#1_quicksort_compare:nnTF}{##4}{##1}
\exp_not:c{#1_quicksort_partition_less_i:nnnn}
\exp_not:c{#1_quicksort_partition_greater_i:nnnn}
}
{##1}{##2}{##3}{##4}
}
\def_long:cNx {#1_quicksort_do_partition_ii_braced:nnnn} 4 {
\exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw}
{
\exp_not:c{#1_quicksort_compare:nnTF}{##4}{##1}
\exp_not:c{#1_quicksort_partition_less_i_braced:nnnn}
\exp_not:c{#1_quicksort_partition_greater_i_braced:nnnn}
}
{##1}{##2}{##3}{##4}
}
\def_long:cNx {#1_quicksort_partition_less_i:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_i:nnnw}{##1}{##2}{{##4}##3}}
\def_long:cNx {#1_quicksort_partition_less_ii:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_ii:nnnw}{##1}{##2}{##3{##4}}}
\def_long:cNx {#1_quicksort_partition_greater_i:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_i:nnnw}{##1}{{##4}##2}{##3}}
\def_long:cNx {#1_quicksort_partition_greater_ii:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_ii:nnnw}{##1}{##2{##4}}{##3}}
\def_long:cNx {#1_quicksort_partition_less_i_braced:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_i_braced:nnnn}{##1}{##2}{{##4}##3}}
\def_long:cNx {#1_quicksort_partition_less_ii_braced:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_ii_braced:nnnn}{##1}{##2}{##3{##4}}}
\def_long:cNx {#1_quicksort_partition_greater_i_braced:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_i_braced:nnnn}{##1}{{##4}##2}{##3}}
\def_long:cNx {#1_quicksort_partition_greater_ii_braced:nnnn} 4{
\exp_not:c{#1_quicksort_do_partition_ii_braced:nnnn}{##1}{##2{##4}}{##3}}
\def_long:cpx {#1_do_quicksort_braced:nnnnw} ##1##2##3##4\q_stop {
\exp_not:c{#1_quicksort_braced:n}{##2}
\exp_not:c{#1_quicksort_function:n}{##1}
\exp_not:c{#1_quicksort_braced:n}{##3}
}
}
\prg_define_quicksort:nnn {prg}{}{}
\let:NN \prg_quicksort_function:n \ERROR
\let:NN \prg_quicksort_compare:nnTF \ERROR
%%
%%
%% End of file `l3prg.sty'.
|