summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/expl3/l3seq.dtx
blob: f9d6f82e2839e08035f6fc8832978e548eabec4f (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
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
% \iffalse
%% File: l3seq.dtx Copyright (C) 1990-2010 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/svnroot/experimental/trunk/
%%
%% 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.
%%
%% -----------------------------------------------------------------------
%
%<*driver|package>
\RequirePackage{l3names}
%</driver|package>
%\fi
\GetIdInfo$Id: l3seq.dtx 1879 2010-03-29 17:48:38Z mittelba $
          {L3 Experimental sequences and stacks}
%\iffalse
%<*driver>
%\fi
\ProvidesFile{\filename.\filenameext}
  [\filedate\space v\fileversion\space\filedescription]
%\iffalse
\documentclass[full]{l3doc}
\begin{document}
\DocInput{\filename.\filenameext}
\end{document}
%</driver>
% \fi
%
%
% \title{The \textsf{l3seq} package\thanks{This file
%         has version number \fileversion, last
%         revised \filedate.}\\
% Sequences}
% \author{\Team}
% \date{\filedate}
% \maketitle
%
% \begin{documentation}
%
% \LaTeX3 implements a data type called `sequences'. These are special
% token lists that can be accessed via special function on the `left'.
% Appending tokens is possible at both ends. Appended token lists can be
% accessed only as a union.  The token lists that form the individual
% items of a sequence might contain any tokens except two internal
% functions that are used to structure sequences (see section internal
% functions below).  It is also possible to map functions on such
% sequences so that they are executed for every item on the sequence.
%
% All functions that return items from a sequence in some \m{tl var.}~assume
% that the \m{tl var.}~is local. See remarks below if you need a global
% returned value.
%
% The defined functions are not orthogonal in the sense that every
% possible variation possible is actually available. If you need a new
% variant use the expansion functions described in the package
% \texttt{l3expan} to build it.
%
% Adding items to the left of a sequence can currently be done with
% either something like "\seq_put_left:Nn" or with a ``stack'' function
% like "\seq_push:Nn" which has the same effect. Maybe one should
% therefore remove the ``left'' functions totally.
%
% \section{Functions for creating/initialising sequences}
%
% \begin{function}{ \seq_new:N |
%                   \seq_new:c }
% \begin{syntax}
%    "\seq_new:N" <sequence>
% \end{syntax}
% Defines <sequence> to be a variable of type "seq".
% \end{function}
%
% \begin{function}{ \seq_clear:N |
%                   \seq_clear:c |
%                  \seq_gclear:N |
%                  \seq_gclear:c }
% \begin{syntax}
%   "\seq_clear:N"  <sequence>
% \end{syntax}
% These functions locally or globally clear <sequence>.
% \end{function}
%
% \begin{function}{ \seq_clear_new:N |
%                   \seq_clear_new:c |
%                  \seq_gclear_new:N |
%                  \seq_gclear_new:c }
% \begin{syntax}
%   "\seq_clear_new:N"  <sequence>
% \end{syntax}
% These functions locally or globally clear <sequence> if it exists or 
% otherwise allocates it.
% \end{function}
%
% \begin{function}{ \seq_set_eq:NN |
%                   \seq_set_eq:cN |
%                   \seq_set_eq:Nc |
%                   \seq_set_eq:cc }
% \begin{syntax}
%   "\seq_set_eq:NN" <seq1> <seq2>
% \end{syntax}
% Function that locally makes <seq1> identical to <seq2>.
% \end{function}
%              
% \begin{function}{ \seq_gset_eq:NN |
%                   \seq_gset_eq:cN |
%                   \seq_gset_eq:Nc |
%                   \seq_gset_eq:cc }
% \begin{syntax}
%   "\seq_gset_eq:NN" <seq1> <seq2>
% \end{syntax}
% Function that globally makes <seq1> identical to <seq2>.
% \end{function}
%
% \begin{function}{%
%                  \seq_concat:NNN |
%                  \seq_concat:ccc |
%                  \seq_gconcat:NNN |
%                  \seq_gconcat:ccc |
% }
% \begin{syntax}
%   "\seq_concat:NNN"  <seq1> <seq2> <seq3>
%   "\seq_gconcat:NNN" <seq1> <seq2> <seq3>
% \end{syntax}
% Function that conatenates <seq2> and <seq3> and locally or globally assigns the
% result to <seq1>.
% \end{function}
%
% \section{Adding data to sequences}
%
% \begin{function}{%
%                  \seq_put_left:Nn |
%                  \seq_put_left:NV |
%                  \seq_put_left:No |
%                  \seq_put_left:Nx |
%                  \seq_put_left:cn |
%                  \seq_put_left:cV |
%                  \seq_put_left:co |
% }
% \begin{syntax}
%   "\seq_put_left:Nn" <sequence> <token list>
% \end{syntax}
% Locally  appends <token list> as a single item to the left
% of <sequence>. <token list> might get expanded before
% appending according to the variant.
% \end{function}
%
% \begin{function}{%
%                  \seq_put_right:Nn |
%                  \seq_put_right:NV |
%                  \seq_put_right:No | 
%                  \seq_put_right:Nx |
%                  \seq_put_right:cn |
%                  \seq_put_right:cV |
%                  \seq_put_right:co |
% }
% \begin{syntax}
%   "\seq_put_right:Nn" <sequence> <token list>
% \end{syntax}
% Locally  appends <token list> as a single item to the right
% of <sequence>. <token list> might get expanded before
% appending according to the variant.
% \end{function}
%
% \begin{function}{%
%                  \seq_gput_left:Nn |
%                  \seq_gput_left:NV |
%                  \seq_gput_left:No |
%                  \seq_gput_left:Nx |
%                  \seq_gput_left:cn |
%                  \seq_gput_left:cV |
%                  \seq_gput_left:co |
% }
% \begin{syntax}
%   "\seq_gput_left:Nn" <sequence> <token list>
% \end{syntax}
% Globally appends <token list> as a single item to the left
% of <sequence>.
% \end{function}
%
% \begin{function}{%
%                  \seq_gput_right:Nn |
%                  \seq_gput_right:NV |
%                  \seq_gput_right:No |
%                  \seq_gput_right:Nx |
%                  \seq_gput_right:cn |
%                  \seq_gput_right:cV |
%                  \seq_gput_right:co |
% }
% \begin{syntax}
%   "\seq_gput_right:Nn" <sequence> <token list>
% \end{syntax}
% Globally appends <token list> as a single item to the right
% of <sequence>.
% \end{function}
%
%
% \section{Working with sequences}
%
% \begin{function}{%
%                  \seq_get:NN |
%                  \seq_get:cN |
% }
% \begin{syntax}
%    "\seq_get:NN" <sequence> <tl var.>
% \end{syntax}
% Functions that locally assign the left-most item of <sequence> to the
% token list variable <tl var.>. Item is not removed from <sequence>! If you
% need a global return value you need to code something like this:
% \begin{quote}
%   "\seq_get:NN" <sequence> "\l_tmpa_tl" \\
%   "\tl_gset_eq:NN" <global tl var.> "\l_tmpa_tl"
% \end{quote}
% But if this kind of construction is used often enough a separate
% function should be provided.
% \end{function}
%
%
% \begin{function}{\seq_map_variable:NNn |
%                  \seq_map_variable:cNn
% }
% \begin{syntax}
%   "\seq_map_variable:NNn" <sequence> <tl var.> \Arg{code using tl var.}
% \end{syntax}
% Every element in <sequence> is assigned to <tl var.> and then <code
% using tl var.> is executed. The operation is not expandable which means
% that it can't be used within write operations etc. However, this
% function can be nested which the others can't.
% \end{function}
%
% \begin{function}{ \seq_map_function:NN |
%                   \seq_map_function:cN }
% \begin{syntax}
%    "\seq_map_function:NN" <sequence> <function>
% \end{syntax}
% This function applies <function> (which must be a function with one
% argument) to every item of <sequence>. <function> is not executed
% within a sub-group so that side effects can be achieved locally. The
% operation is not expandable which means that it can't be used within
% write operations etc.
%
% In the current implementation the next functions are more efficient and
% should be preferred.
% \end{function}
%
% \begin{function}{\seq_map_inline:Nn |
%                  \seq_map_inline:cn
% }
% \begin{syntax}
%   "\seq_map_inline:Nn" <sequence> \Arg{inline function}
% \end{syntax}
% Applies <inline function> (which should be the direct coding for a
% function with one argument (i.e.\ use "#1" as the place holder for
% this argument)) to every item of <sequence>.  <inline function> is not
% executed within a sub-group so that side effects can be achieved locally.
% The operation is not expandable which means that it can't be used
% within write operations etc.
% \end{function}
%
% \begin{function}{ \seq_map_break: | \seq_map_break:n }
% These functions are used to break out of a mapping function at the point
% of execution. (Please do not put `|\q_stop|' inside a <seq> that uses
% these functions.)
% \end{function}
%
% \begin{function}{ \seq_show:N |
%                   \seq_show:c }
% \begin{syntax}
%   "\seq_show:N" <sequence>
% \end{syntax}
% Function that pauses the compilation and displays <seq> in the terminal
% output and in the log file. (Usually used for diagnostic purposes.)
% \end{function}
%
% \begin{function}{ \seq_display:N |
%                   \seq_display:c }
% \begin{syntax}
%   "\seq_display:N" <sequence>
% \end{syntax}
% As with "\seq_show:N" but pretty prints the output one line per element.
% \end{function}
%
% \begin{function}{ \seq_remove_duplicates:N  |
%                   \seq_gremove_duplicates:N }
% \begin{syntax}
%   "\seq_gremove_duplicates:N" <seq>
% \end{syntax}
% Function that removes any duplicate entries in <seq>.
% \end{function}
%
% \section{Predicates and conditionals}
%
% \begin{function}{ \seq_if_empty_p:N / (EXP) | 
%                   \seq_if_empty_p:c / (EXP) }
% \begin{syntax}
%   "\seq_if_empty_p:N" <sequence>
% \end{syntax}
% This predicate returns `true' if <sequence> is `empty' i.e., doesn't
% contain any items. Note that this is `false' even if the <sequence> only
% contains a single empty item.
% \end{function}
%
% \begin{function}{ \seq_if_empty:N / (TF) |
%                   \seq_if_empty:c / (TF) }
% \begin{syntax}
%   "\seq_if_empty:NTF" <sequence> \Arg{true code} \Arg{false code}
% \end{syntax}
% Set of conditionals that test whether or not a particular <sequence>
% is empty and if so executes either <true code> or <false code>.
% \end{function}
%
% \begin{function}{ \seq_if_in:Nn / (TF) |
%                   \seq_if_in:NV / (TF) |
%                   \seq_if_in:cn / (TF) |
%                   \seq_if_in:cV / (TF) |
%                   \seq_if_in:co / (TF) |
%                   \seq_if_in:cx / (TF) }
% \begin{syntax}
%   "\seq_if_in:NnTF" <sequence> \Arg{item} \Arg{true code} \Arg{false code}
% \end{syntax}
% Functions that test if <item> is in <sequence>. Depending on the result
% either <true code> or <false code> is executed.
% \end{function}
%
% \section{Internal functions}
%
% \begin{function}{\seq_if_empty_err:N}
% \begin{syntax}
%   "\seq_if_empty_err:N" <sequence>
% \end{syntax}
% Signals an \LaTeX3 error if <sequence> is empty.
% \end{function}
%
% \begin{function}{\seq_pop_aux:nnNN}
% \begin{syntax}
%   "\seq_pop_aux:nnNN" <assign1> <assign2> <sequence> <tl var.>
% \end{syntax}
% Function that assigns the left-most item of <sequence> to <tl var.> using
% <assign1> and assigns the tail to <sequence> using <assign2>. This
% function could be used to implement a global return function.
% \end{function}
%
% \begin{function}{%
%                  \seq_get_aux:w |
%                  \seq_pop_aux:w |
%                  \seq_put_aux:Nnn |
%                  \seq_put_aux:w |
% }
% Functions used to implement put and get operations. They  are not for
% meant for direct use.
% \end{function}
%
% \begin{function}{ \seq_elt:w    |
%                   \seq_elt_end: }
% Functions (usually used as constants) that separates items within a
% sequence. They might get special meaning during mapping operations and
% are not supposed to show up as tokens within an item appended to a
% sequence.
% \end{function}
%
% \section{Functions for `Sequence Stacks'}
%
% Special sequences in \LaTeX3 are `stacks' with their usual operations
% of `push', `pop', and `top'. They are internally implemented as
% sequences and share some of the functions (like "\seq_new:N" etc.)
%
% \begin{function}{%
%                  \seq_push:Nn |
%                  \seq_push:NV |
%                  \seq_push:No |
%                  \seq_push:cn |
%                  \seq_gpush:Nn |
%                  \seq_gpush:NV |
%                  \seq_gpush:No |
%                  \seq_gpush:Nv |
%                  \seq_gpush:cn |
% }
% \begin{syntax}
%   "\seq_push:Nn" <stack> \Arg{token list}
% \end{syntax}
% Locally or globally pushes <token list> as a single item onto the
% <stack>.
% \end{function}
%
% \begin{function}{%
%                  \seq_pop:NN |
%                  \seq_pop:cN |
%                  \seq_gpop:NN |
%                  \seq_gpop:cN |
% }
% \begin{syntax}
%    "\seq_pop:NN" <stack> <tl var.>
% \end{syntax}
% Functions that assign the top item of <stack> to <tl var.>
% and removes it from <stack>!
% \end{function}
%
% \begin{function}{%
%                  \seq_top:NN |
%                  \seq_top:cN |
% }
% \begin{syntax}
%    "\seq_top:NN" <stack> <tl var.>
% \end{syntax}
% Functions that locally assign the top item of <stack> to the <tl var.>.
% Item is \emph{not} removed from <stack>!
% \end{function}
%
% \end{documentation}
%
% \begin{implementation}
%
% \section{\pkg{l3seq} implementation}
%
%    \begin{macrocode}
%<*package>
\ProvidesExplPackage
  {\filename}{\filedate}{\fileversion}{\filedescription}
\package_check_loaded_expl:
%</package>
%    \end{macrocode}
%
% A sequence is a control sequence whose top-level expansion is of the
% form `|\seq_elt:w| \m{text$\sb1$} |\seq_elt_end:| \ldots{}
% |\seq_elt:w| \meta{text$\sb{n}$} \ldots'. We use explicit delimiters
% instead of braces around \m{text} to allow efficient searching for
% an item in the sequence.
%
% \begin{macro}{\seq_elt:w}
% \begin{macro}{\seq_elt_end:}
%    We allocate the delimiters and make them errors if executed.
%    \begin{macrocode}
%<*initex|package>
\cs_new:Npn \seq_elt:w {\ERROR}
\cs_new:Npn \seq_elt_end: {\ERROR}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Allocating and initialisation}
%
% \begin{macro}{\seq_new:N}
% \begin{macro}{\seq_new:c}
%    Sequences are implemented using token lists.
%    \begin{macrocode}
\cs_new_eq:NN \seq_new:N \tl_new:N
\cs_new_eq:NN \seq_new:c \tl_new:c
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_clear:N}
% \begin{macro}{\seq_clear:c}
% \begin{macro}{\seq_gclear:N}
% \begin{macro}{\seq_gclear:c}
%    Clearing a sequence is the same as clearing a token list.
%    \begin{macrocode}
\cs_new_eq:NN \seq_clear:N  \tl_clear:N
\cs_new_eq:NN \seq_clear:c  \tl_clear:c
\cs_new_eq:NN \seq_gclear:N \tl_gclear:N
\cs_new_eq:NN \seq_gclear:c \tl_gclear:c
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_clear_new:N}
% \begin{macro}{\seq_clear_new:c}
% \begin{macro}{\seq_gclear_new:N}
% \begin{macro}{\seq_gclear_new:c}
%    Clearing a sequence is the same as clearing a token list.
%    \begin{macrocode}
\cs_new_eq:NN \seq_clear_new:N  \tl_clear_new:N
\cs_new_eq:NN \seq_clear_new:c  \tl_clear_new:c
\cs_new_eq:NN \seq_gclear_new:N \tl_gclear_new:N
\cs_new_eq:NN \seq_gclear_new:c \tl_gclear_new:c
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}   
%                              
% \begin{macro}{\seq_set_eq:NN}
% \begin{macro}{\seq_set_eq:Nc} 
% \begin{macro}{\seq_set_eq:cN}
% \begin{macro}{\seq_set_eq:cc} 
%    We can set one "seq" equal to another.
%    \begin{macrocode}                
\cs_new_eq:NN \seq_set_eq:NN \cs_set_eq:NN   
\cs_new_eq:NN \seq_set_eq:cN \cs_set_eq:cN   
\cs_new_eq:NN \seq_set_eq:Nc \cs_set_eq:Nc   
\cs_new_eq:NN \seq_set_eq:cc \cs_set_eq:cc                        
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_gset_eq:NN}
% \begin{macro}{\seq_gset_eq:cN}
% \begin{macro}{\seq_gset_eq:Nc}
% \begin{macro}{\seq_gset_eq:cc}
%    And of course globally which seems to be needed far more
%    often.\footnote{To save a bit of space these functions could be made
%    identical to those from the tl or clist module.}
%    \begin{macrocode}
\cs_new_eq:NN \seq_gset_eq:NN \cs_gset_eq:NN
\cs_new_eq:NN \seq_gset_eq:cN \cs_gset_eq:cN
\cs_new_eq:NN \seq_gset_eq:Nc \cs_gset_eq:Nc
\cs_new_eq:NN \seq_gset_eq:cc \cs_gset_eq:cc
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_concat:NNN,\seq_concat:ccc}
%    |\seq_concat:NNN| \m{seq~1} \m{seq~2} \m{seq~3} will locally
%    assign \m{seq~1} the concatenation of \m{seq~2} and \m{seq~3}.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \seq_concat:NNN #1#2#3 {
  \tl_set:Nx #1 { \exp_not:V #2 \exp_not:V #3 }
}
\cs_generate_variant:Nn \seq_concat:NNN {ccc}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\seq_gconcat:NNN,\seq_gconcat:ccc}
%    |\seq_gconcat:NNN| \m{seq~1} \m{seq~2} \m{seq~3} will globally
%    assign \m{seq~1} the concatenation of \m{seq~2} and \m{seq~3}.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \seq_gconcat:NNN #1#2#3 {
  \tl_gset:Nx #1 { \exp_not:V #2 \exp_not:V #3 }
}
\cs_generate_variant:Nn \seq_gconcat:NNN {ccc}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Predicates and conditionals}
%
% \begin{macro}{\seq_if_empty_p:N,\seq_if_empty_p:c}
% \begin{macro}[TF]{\seq_if_empty:N,\seq_if_empty:c}
%    A predicate which evaluates to |\c_true_bool| iff the sequence is empty.
%    \begin{macrocode}
\prg_new_eq_conditional:NNn \seq_if_empty:N \tl_if_empty:N {p,TF,T,F}
\prg_new_eq_conditional:NNn \seq_if_empty:c \tl_if_empty:c {p,TF,T,F}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \begin{macro}{\seq_if_empty_err:N}
%   Signals an error if the sequence is empty.
%    \begin{macrocode}
\cs_new_nopar:Npn \seq_if_empty_err:N #1 {
  \if_meaning:w #1 \c_empty_tl
%    \end{macrocode}
%    As I said before, I don't think we need to provide checks for this
%    kind of error, since it is a severe internal macro package error
%    that can not be produced by the user directly. Can it? So the
%    next line of code should be probably removed.
%    (Will: I have no idea what this comment means.)
%    \begin{macrocode}
    \tl_clear:N \l_kernel_testa_tl % catch prefixes
    \msg_kernel_bug:x {Empty~sequence~`\token_to_str:N#1'}
  \fi:
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}[TF]{\seq_if_in:Nn,\seq_if_in:NV,\seq_if_in:cn,
%   \seq_if_in:cV,\seq_if_in:co,\seq_if_in:cx}
%    |\seq_if_in:NnTF| \m{seq}\m{item} \m{true~case} \m{false~case}
%    will check whether \m{item} is in \m{seq} and then either execute
%    the \m{true~case} or the \m{false~case}. \m{true~case} and
%    \m{false~case} may contain incomplete |\if_charcode:w|
%    statements.
%
%    Note that |##2| in the definition below for "\seq_tmp:w" contains
%    exactly one token which we can compare with |\q_no_value|.
%    \begin{macrocode}
\prg_new_protected_conditional:Nnn \seq_if_in:Nn {TF,T,F} {
  \cs_set:Npn \seq_tmp:w ##1 \seq_elt:w #2 \seq_elt_end: ##2##3 \q_stop {
    \if_meaning:w \q_no_value ##2
      \prg_return_false: \else: \prg_return_true: \fi:
  }
  \exp_after:wN \seq_tmp:w #1 \seq_elt:w #2 \seq_elt_end: \q_no_value \q_stop
}
%    \end{macrocode}
%    \begin{macrocode}
\cs_generate_variant:Nn \seq_if_in:NnTF { NV, cV, co, c, cx}
\cs_generate_variant:Nn \seq_if_in:NnT  { NV, cV, co, c, cx}
\cs_generate_variant:Nn \seq_if_in:NnF  { NV, cV, co, c, cx}
%    \end{macrocode}
% \end{macro}
%
% \subsection{Getting data out}
%
% \begin{macro}{\seq_get:NN}
% \begin{macro}{\seq_get:cN}
% \begin{macro}{\seq_get_aux:w}
%    |\seq_get:NN |\meta{sequence}\meta{cmd} defines \meta{cmd} to be the
%    left-most element of \meta{sequence}.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \seq_get:NN #1 {
  \seq_if_empty_err:N #1
  \exp_after:wN \seq_get_aux:w #1 \q_stop
}
\cs_new_protected:Npn \seq_get_aux:w \seq_elt:w #1 \seq_elt_end: #2 \q_stop #3 {
  \tl_set:Nn #3 {#1}
}
\cs_generate_variant:Nn \seq_get:NN {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_pop_aux:nnNN}
% \begin{macro}{\seq_pop_aux:w}
%    |\seq_pop_aux:nnNN| \meta{def$\sb1$} \meta{def$\sb2$} \meta{sequence}
%    \meta{cmd} assigns the left_most element of \meta{sequence} to
%    \meta{cmd} using \meta{def$\sb2$}, and assigns the tail of
%    \meta{sequence} to \meta{sequence} using \meta{def$\sb1$}.
%    \begin{macrocode}
\cs_new_protected:Npn \seq_pop_aux:nnNN #1#2#3 {
  \seq_if_empty_err:N #3
  \exp_after:wN \seq_pop_aux:w #3 \q_stop #1#2#3
}
\cs_new_protected:Npn \seq_pop_aux:w 
    \seq_elt:w #1 \seq_elt_end: #2\q_stop #3#4#5#6 {
  #3 #5 {#2}
  #4 #6 {#1}
}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_show:N}
% \begin{macro}{\seq_show:c}
%    \begin{macrocode}
\cs_new_eq:NN \seq_show:N \tl_show:N
\cs_new_eq:NN \seq_show:c \tl_show:c
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_display:N}
% \begin{macro}{\seq_display:c}
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \seq_display:N #1 {
  \iow_term:x { Sequence~\token_to_str:N #1~contains~
                   the~elements~(without~outer~braces): }
  \toks_clear:N \l_tmpa_toks
  \seq_map_inline:Nn #1 {
    \toks_if_empty:NF  \l_tmpa_toks {
      \toks_put_right:Nx \l_tmpa_toks {^^J>~}
    }
    \toks_put_right:Nx \l_tmpa_toks {
      \c_space_tl \iow_char:N \{ \exp_not:n {##1} \iow_char:N \}
    }
  }
  \toks_show:N \l_tmpa_toks
}
\cs_generate_variant:Nn \seq_display:N {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
% \subsection{Putting data in}
%
% \begin{macro}{\seq_put_aux:Nnn}
% \begin{macro}{\seq_put_aux:w}
%    |\seq_put_aux:Nnn| \meta{sequence} \meta{left} \meta{right} adds the
%    elements specified by \meta{left} to the left of \meta{sequence}, and
%    those specified by \meta{right} to the right.
%    \begin{macrocode}
\cs_new_protected:Npn \seq_put_aux:Nnn #1 {
  \exp_after:wN \seq_put_aux:w #1 \q_stop #1
}
\cs_new_protected:Npn \seq_put_aux:w #1\q_stop #2#3#4 { \tl_set:Nn #2 {#3#1#4} }
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_put_left:Nn}
% \begin{macro}{\seq_put_left:NV}
% \begin{macro}{\seq_put_left:No}
% \begin{macro}{\seq_put_left:Nx}
% \begin{macro}{\seq_put_left:cn}
% \begin{macro}{\seq_put_left:cV}
% \begin{macro}{\seq_put_left:co}
% \begin{macro}{\seq_put_right:Nn}
% \begin{macro}{\seq_put_right:No}
% \begin{macro}{\seq_put_right:NV}
% \begin{macro}{\seq_put_right:Nx}
% \begin{macro}{\seq_put_right:cn}
% \begin{macro}{\seq_put_right:cV}
% \begin{macro}{\seq_put_right:co}
%    Here are the usual operations for adding to the left and right.
%    \begin{macrocode}
\cs_new_protected:Npn \seq_put_left:Nn #1#2 {
  \seq_put_aux:Nnn #1 {\seq_elt:w #2\seq_elt_end:} {}
}
%    \end{macrocode}
%    We can't put in a |\prg_do_nothing:| instead of |{}| above since this argument 
%    is passed literally (and we would end up with many |\prg_do_nothing:|s inside
%    the sequences).
%    \begin{macrocode}
\cs_generate_variant:Nn \seq_put_left:Nn {NV,No,Nx,c,cV,co}
%    \end{macrocode}
%    \begin{macrocode}
\cs_new_protected:Npn \seq_put_right:Nn #1#2{
        \seq_put_aux:Nnn #1{}{\seq_elt:w #2\seq_elt_end:}}
%    \end{macrocode}
%    \begin{macrocode}
\cs_generate_variant:Nn \seq_put_right:Nn {NV,No,Nx,c,cV,co}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_gput_left:Nn}
% \begin{macro}{\seq_gput_left:NV}
% \begin{macro}{\seq_gput_left:No}
% \begin{macro}{\seq_gput_left:Nx}
% \begin{macro}{\seq_gput_left:cn}
% \begin{macro}{\seq_gput_left:cV}
% \begin{macro}{\seq_gput_left:co}
% \begin{macro}{\seq_gput_right:Nn}
% \begin{macro}{\seq_gput_right:NV}
% \begin{macro}{\seq_gput_right:No}
% \begin{macro}{\seq_gput_right:Nx}
% \begin{macro}{\seq_gput_right:cn}
% \begin{macro}{\seq_gput_right:cV}
% \begin{macro}{\seq_gput_right:co}
%    \begin{macrocode}
\cs_new_protected:Npn \seq_gput_left:Nn {
%<*check>
  \pref_global_chk:
%</check>
%<*!check> 
  \pref_global:D
%</!check>
  \seq_put_left:Nn
}
%    \end{macrocode}
%    \begin{macrocode}
\cs_new_protected:Npn \seq_gput_right:Nn {
%<*check>
  \pref_global_chk:
%</check>
%<*!check> 
  \pref_global:D
%</!check>
  \seq_put_right:Nn
}
%    \end{macrocode}
%    \begin{macrocode}
\cs_generate_variant:Nn \seq_gput_left:Nn {NV,No,Nx,c,cV,co}
%    \end{macrocode}
%    \begin{macrocode}
\cs_generate_variant:Nn \seq_gput_right:Nn {NV,No,Nx,c,cV,co}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
%
% \subsection{Mapping}
%
% \begin{macro}{\seq_map_variable:NNn}
% \begin{macro}{\seq_map_variable:cNn}
% \begin{macro}[aux]{\seq_map_variable_aux:Nnw}
%   Nothing spectacular here.
%    \begin{macrocode}
\cs_new_protected:Npn \seq_map_variable_aux:Nnw #1#2 \seq_elt:w #3 \seq_elt_end: {
  \tl_set:Nn #1 {#3}
  \quark_if_nil:NT #1 \seq_map_break:
  #2
  \seq_map_variable_aux:Nnw #1{#2}
}
\cs_new_protected:Npn \seq_map_variable:NNn #1#2#3 {
  \tl_set:Nn #2 {\seq_map_variable_aux:Nnw #2{#3}}
  \exp_after:wN #2 #1 \seq_elt:w \q_nil\seq_elt_end: \q_stop
}
\cs_generate_variant:Nn \seq_map_variable:NNn {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_map_break:}
% \begin{macro}{\seq_map_break:n}
% Terminate a mapping function at the point of execution. The latter
% takes an argument to be executed after cleaning up the map.
%    \begin{macrocode}
\cs_new_eq:NN \seq_map_break: \use_none_delimit_by_q_stop:w
\cs_new_eq:NN \seq_map_break:n \use_i_delimit_by_q_stop:nw
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_map_function:NN}
% \begin{macro}{\seq_map_function:cN}
%    |\seq_map_function:NN| \meta{sequence} \meta{cmd} applies \meta{cmd} to each
%    element of \meta{sequence}, from left to right. Since we don't have
%    braces, this implementation is not very efficient. It might be
%    better to say that \meta{cmd} must be a function with one argument
%    that is delimited by |\seq_elt_end:|.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \seq_map_function:NN #1#2 {
  \cs_set:Npn \seq_elt:w ##1 \seq_elt_end: {#2{##1}}
  #1 \use_none:n \q_stop
  \cs_set_eq:NN \seq_elt:w \ERROR
}
\cs_generate_variant:Nn \seq_map_function:NN {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_map_inline:Nn}
% \begin{macro}{\seq_map_inline:cn}
%    When no braces are used, this version of mapping seems more
%    natural.
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \seq_map_inline:Nn #1#2 {
  \cs_set:Npn \seq_elt:w ##1 \seq_elt_end: {#2}
  #1 \use_none:n \q_stop
  \cs_set_eq:NN \seq_elt:w \ERROR
}
\cs_generate_variant:Nn \seq_map_inline:Nn {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
% \subsection{Manipulation}
%
%  \begin{macro}[aux]{\l_clist_remove_clist}
%  A common scratch space for the removal routines.
%    \begin{macrocode}
\seq_new:N \l_seq_remove_seq
%    \end{macrocode}
%  \end{macro}
%
%  \begin{macro}[aux]{\seq_remove_duplicates_aux:NN}
%  \begin{macro}[aux]{\seq_remove_duplicates_aux:n}
%  \begin{macro}{\seq_remove_duplicates:N}
%  \begin{macro}{\seq_gremove_duplicates:N}
%  Copied from "\clist_remove_duplicates".
%    \begin{macrocode}
\cs_new_protected:Npn \seq_remove_duplicates_aux:NN #1#2 {
  \seq_clear:N \l_seq_remove_seq
  \seq_map_function:NN #2 \seq_remove_duplicates_aux:n
  #1 #2 \l_seq_remove_seq
}
\cs_new_protected:Npn \seq_remove_duplicates_aux:n #1 {
  \seq_if_in:NnF \l_seq_remove_seq {#1} {
    \seq_put_right:Nn \l_seq_remove_seq {#1}
  }
}
%    \end{macrocode}
%    \begin{macrocode}
\cs_new_protected_nopar:Npn \seq_remove_duplicates:N {
  \seq_remove_duplicates_aux:NN \seq_set_eq:NN
}
\cs_new_protected_nopar:Npn \seq_gremove_duplicates:N {
  \seq_remove_duplicates_aux:NN \seq_gset_eq:NN
}
%    \end{macrocode}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%  \end{macro}
%
% \subsection{Sequence stacks}
%
% \begin{macro}{\seq_push:Nn}
% \begin{macro}{\seq_push:NV}
% \begin{macro}{\seq_push:No}
% \begin{macro}{\seq_push:cn}
% \begin{macro}{\seq_pop:NN}
% \begin{macro}{\seq_pop:cN}
%    Since sequences can be used as stacks, we ought to have both
%    `push' and `pop'. In most cases they are nothing more then new
%    names for old functions.
%    \begin{macrocode}
\cs_new_eq:NN \seq_push:Nn \seq_put_left:Nn
\cs_new_eq:NN \seq_push:NV \seq_put_left:NV
\cs_new_eq:NN \seq_push:No \seq_put_left:No
\cs_new_eq:NN \seq_push:cn \seq_put_left:cn
\cs_new_protected_nopar:Npn \seq_pop:NN { \seq_pop_aux:nnNN \tl_set:Nn \tl_set:Nn }
\cs_generate_variant:Nn \seq_pop:NN {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_gpush:Nn}
% \begin{macro}{\seq_gpush:NV}
% \begin{macro}{\seq_gpush:No}
% \begin{macro}{\seq_gpush:cn}
% \begin{macro}{\seq_gpush:Nv}
% \begin{macro}{\seq_gpop:NN}
% \begin{macro}{\seq_gpop:cN}
%    I don't agree with Denys that one needs only local stacks,
%    actually I believe that one will probably need the functions
%    here more often. In case of |\seq_gpop:NN| the value is
%    nevertheless returned locally.
%    \begin{macrocode}
\cs_new_eq:NN  \seq_gpush:Nn \seq_gput_left:Nn
\cs_new_protected_nopar:Npn \seq_gpop:NN  { \seq_pop_aux:nnNN \tl_gset:Nn \tl_set:Nn }
\cs_generate_variant:Nn \seq_gpush:Nn {NV,No,c,Nv}
\cs_generate_variant:Nn  \seq_gpop:NN  {c}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\seq_top:NN}
% \begin{macro}{\seq_top:cN}
%    Looking at the top element of the stack without removing it is
%    done with this operation.
%    \begin{macrocode}
\cs_new_eq:NN \seq_top:NN \seq_get:NN
\cs_new_eq:NN \seq_top:cN \seq_get:cN
%    \end{macrocode}
% \end{macro}
% \end{macro}
%
%
%    \begin{macrocode}
%</initex|package>
%    \end{macrocode}
%
%    Show token usage:
%    \begin{macrocode}
%<*showmemory>
%\showMemUsage
%</showmemory>
%    \end{macrocode}
%
% \end{implementation}
% \PrintIndex
%
% \endinput