summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/l3kernel/l3int.dtx
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2019-09-30 03:00:43 +0000
committerNorbert Preining <norbert@preining.info>2019-09-30 03:00:43 +0000
commitbbbe8128e7ae9d816a221377dbf5ff3969bb203b (patch)
tree0283a521760b879b30e61872f14f235645745675 /macros/latex/contrib/l3kernel/l3int.dtx
parent14ce8b68fe7df49e8a8891bb94c63b9a846da232 (diff)
CTAN sync 201909300300
Diffstat (limited to 'macros/latex/contrib/l3kernel/l3int.dtx')
-rw-r--r--macros/latex/contrib/l3kernel/l3int.dtx138
1 files changed, 47 insertions, 91 deletions
diff --git a/macros/latex/contrib/l3kernel/l3int.dtx b/macros/latex/contrib/l3kernel/l3int.dtx
index 1cd7e62c93..042f4d656c 100644
--- a/macros/latex/contrib/l3kernel/l3int.dtx
+++ b/macros/latex/contrib/l3kernel/l3int.dtx
@@ -43,7 +43,7 @@
% }^^A
% }
%
-% \date{Released 2019-09-19}
+% \date{Released 2019-09-28}
%
% \maketitle
%
@@ -134,6 +134,14 @@
% since the digit~\texttt{9} is not part of the expression.
% \end{function}
%
+% \begin{function}[EXP, added = 2018-11-03]{\int_sign:n}
+% \begin{syntax}
+% \cs{int_sign:n} \Arg{intexpr}
+% \end{syntax}
+% Evaluates the \meta{integer expression} then leaves $1$ or $0$ or
+% $-1$ in the input stream according to the sign of the result.
+% \end{function}
+%
% \begin{function}[EXP, updated = 2012-09-26]{\int_abs:n}
% \begin{syntax}
% \cs{int_abs:n} \Arg{integer expression}
@@ -1053,8 +1061,6 @@
% or directly in the input stream.
% When debugging, use parentheses to catch early termination.
% \begin{macrocode}
-\__kernel_patch_args:nNNpn
- { { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_eval:n } }
\cs_new:Npn \int_eval:n #1
{ \int_value:w \@@_eval:w #1 \@@_eval_end: }
\cs_new:Npn \int_eval:w { \int_value:w \@@_eval:w }
@@ -1062,6 +1068,31 @@
% \end{macro}
% \end{macro}
%
+% \begin{macro}[EXP]{\int_sign:n, \@@_sign:Nw}
+% See \cs{int_abs:n}. Evaluate the expression once (and when
+% debugging is enabled, check that the expression is well-formed),
+% then test the first character to determine the sign. This is
+% wrapped in \cs{int_value:w} \ldots{} \cs{exp_stop_f:} to ensure a
+% fixed number of expansions and to avoid dealing with closing the
+% conditionals.
+% \begin{macrocode}
+\cs_new:Npn \int_sign:n #1
+ {
+ \int_value:w \exp_after:wN \@@_sign:Nw
+ \int_value:w \@@_eval:w #1 \@@_eval_end: ;
+ \exp_stop_f:
+ }
+\cs_new:Npn \@@_sign:Nw #1#2 ;
+ {
+ \if_meaning:w 0 #1
+ 0
+ \else:
+ \if_meaning:w - #1 - \fi: 1
+ \fi:
+ }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}[EXP]{\int_abs:n}
% \begin{macro}[EXP]{\@@_abs:N}
% \UnitTested
@@ -1074,8 +1105,6 @@
% evaluation. The absolute value is obtained by removing a leading
% sign if any. All three functions expand in two steps.
% \begin{macrocode}
-\__kernel_patch_args:nNNpn
- { { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_abs:n } }
\cs_new:Npn \int_abs:n #1
{
\int_value:w \exp_after:wN \@@_abs:N
@@ -1084,11 +1113,6 @@
}
\cs_new:Npn \@@_abs:N #1
{ \if_meaning:w - #1 \else: \exp_after:wN #1 \fi: }
-\__kernel_patch_args:nNNpn
- {
- { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_max:nn }
- { \__kernel_chk_expr:nNnN {#2} \@@_eval:w { } \int_max:nn }
- }
\cs_set:Npn \int_max:nn #1#2
{
\int_value:w \exp_after:wN \@@_maxmin:wwN
@@ -1097,11 +1121,6 @@
>
\exp_stop_f:
}
-\__kernel_patch_args:nNNpn
- {
- { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_min:nn }
- { \__kernel_chk_expr:nNnN {#2} \@@_eval:w { } \int_min:nn }
- }
\cs_set:Npn \int_min:nn #1#2
{
\int_value:w \exp_after:wN \@@_maxmin:wwN
@@ -1146,11 +1165,6 @@
% truncating behaviour that we want. The details are thanks to Heiko
% Oberdiek: getting things right in all cases is not so easy.
% \begin{macrocode}
-\__kernel_patch_args:nNNpn
- {
- { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_div_truncate:nn }
- { \__kernel_chk_expr:nNnN {#2} \@@_eval:w { } \int_div_truncate:nn }
- }
\cs_new:Npn \int_div_truncate:nn #1#2
{
\int_value:w \@@_eval:w
@@ -1180,11 +1194,6 @@
% \end{macrocode}
% Finally there's the modulus operation.
% \begin{macrocode}
-\__kernel_patch_args:nNNpn
- {
- { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_mod:nn }
- { \__kernel_chk_expr:nNnN {#2} \@@_eval:w { } \int_mod:nn }
- }
\cs_new:Npn \int_mod:nn #1#2
{
\int_value:w \@@_eval:w \exp_after:wN \@@_mod:ww
@@ -1254,10 +1263,6 @@
% We cannot use \cs{int_gset:Nn} because (when |check-declarations| is
% enabled) this runs some checks that constants would fail.
% \begin{macrocode}
-\__kernel_patch_args:nnnNNpn
- { \__kernel_chk_var_scope:NN c #1 }
- { }
- { {#1} { \__kernel_chk_expr:nNnN {#2} \@@_eval:w { } \int_const:Nn } }
\cs_new_protected:Npn \int_const:Nn #1#2
{
\int_compare:nNnTF {#2} < \c_zero_int
@@ -1303,9 +1308,7 @@
% \UnitTested
% Functions that reset an \meta{integer} register to zero.
% \begin{macrocode}
-\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \int_zero:N #1 { #1 = \c_zero_int }
-\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \int_gzero:N #1 { \tex_global:D #1 = \c_zero_int }
\cs_generate_variant:Nn \int_zero:N { c }
\cs_generate_variant:Nn \int_gzero:N { c }
@@ -1335,10 +1338,8 @@
% another. Check that assigned integer is local/global. No need to
% check that the other one is defined as \TeX{} does it for us.
% \begin{macrocode}
-\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \int_set_eq:NN #1#2 { #1 = #2 }
\cs_generate_variant:Nn \int_set_eq:NN { c , Nc , cc }
-\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \int_gset_eq:NN #1#2 { \tex_global:D #1 = #2 }
\cs_generate_variant:Nn \int_gset_eq:NN { c , Nc , cc }
% \end{macrocode}
@@ -1357,22 +1358,6 @@
%
% \subsection{Setting and incrementing integers}
%
-% Several functions here have a signature |:Nn| and are such that when
-% debugging, the first argument should be checked to be a local/global
-% variable and the second should be wrapped in code for an expression.
-% The temporary function \cs{@@_tmp:w} finds the name |#3| of the
-% function being redefined and writes the appropriate patch.
-% \begin{macrocode}
-\cs_set_protected:Npn \@@_tmp:w #1#2#3
- {
- \__kernel_patch_args:nnnNNpn
- { #1 ##1 }
- { }
- { {##1} { \__kernel_chk_expr:nNnN {##2} \@@_eval:w { } #3 } }
- #2 #3
- }
-% \end{macrocode}
-%
% \begin{macro}{\int_add:Nn, \int_add:cn}
% \UnitTested
% \begin{macro}{\int_gadd:Nn, \int_gadd:cn}
@@ -1381,21 +1366,14 @@
% \UnitTested
% \begin{macro}{\int_gsub:Nn, \int_gsub:cn}
% \UnitTested
-% Adding and subtracting to and from a counter. For each function,
-% the debugging code produced by \cs{@@_tmp:w} checks that the
-% assigned variable is correctly local/global and wraps the
-% expression in some checking code.
+% Adding and subtracting to and from a counter.
% \begin{macrocode}
-\@@_tmp:w \__kernel_chk_var_local:N
\cs_new_protected:Npn \int_add:Nn #1#2
{ \tex_advance:D #1 by \@@_eval:w #2 \@@_eval_end: }
-\@@_tmp:w \__kernel_chk_var_local:N
\cs_new_protected:Npn \int_sub:Nn #1#2
{ \tex_advance:D #1 by - \@@_eval:w #2 \@@_eval_end: }
-\@@_tmp:w \__kernel_chk_var_global:N
\cs_new_protected:Npn \int_gadd:Nn #1#2
{ \tex_global:D \tex_advance:D #1 by \@@_eval:w #2 \@@_eval_end: }
-\@@_tmp:w \__kernel_chk_var_global:N
\cs_new_protected:Npn \int_gsub:Nn #1#2
{ \tex_global:D \tex_advance:D #1 by - \@@_eval:w #2 \@@_eval_end: }
\cs_generate_variant:Nn \int_add:Nn { c }
@@ -1419,16 +1397,12 @@
% Incrementing and decrementing of integer registers is done with
% the following functions.
% \begin{macrocode}
-\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \int_incr:N #1
{ \tex_advance:D #1 \c_one_int }
-\__kernel_patch:nnNNpn { \__kernel_chk_var_local:N #1 } { }
\cs_new_protected:Npn \int_decr:N #1
{ \tex_advance:D #1 - \c_one_int }
-\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \int_gincr:N #1
{ \tex_global:D \tex_advance:D #1 \c_one_int }
-\__kernel_patch:nnNNpn { \__kernel_chk_var_global:N #1 } { }
\cs_new_protected:Npn \int_gdecr:N #1
{ \tex_global:D \tex_advance:D #1 - \c_one_int }
\cs_generate_variant:Nn \int_incr:N { c }
@@ -1446,14 +1420,10 @@
% \begin{macro}{\int_gset:Nn, \int_gset:cn}
% \UnitTested
% As integers are register-based \TeX{} issues an error
-% if they are not defined. Thus there is no need to check their
-% existence as for token list variables. However, the code that
-% checks whether the assignment is local or global is still needed.
+% if they are not defined.
% \begin{macrocode}
-\@@_tmp:w \__kernel_chk_var_local:N
\cs_new_protected:Npn \int_set:Nn #1#2
{ #1 ~ \@@_eval:w #2 \@@_eval_end: }
-\@@_tmp:w \__kernel_chk_var_global:N
\cs_new_protected:Npn \int_gset:Nn #1#2
{ \tex_global:D #1 ~ \@@_eval:w #2 \@@_eval_end: }
\cs_generate_variant:Nn \int_set:Nn { c }
@@ -1657,12 +1627,6 @@
% \UnitTested
% More efficient but less natural in typing.
% \begin{macrocode}
-\__kernel_patch_conditional_args:nNNpnn
- {
- { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_compare:nNn }
- { \@@_eval_end: #2 }
- { \__kernel_chk_expr:nNnN {#3} \@@_eval:w { } \int_compare:nNn }
- }
\prg_new_conditional:Npnn \int_compare:nNn #1#2#3 { p , T , F , TF }
{
\if_int_compare:w \@@_eval:w #1 #2 \@@_eval:w #3 \@@_eval_end:
@@ -1722,8 +1686,6 @@
% \UnitTested
% A predicate function.
% \begin{macrocode}
-\__kernel_patch_conditional_args:nNNpnn
- { { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_if_odd:n } }
\prg_new_conditional:Npnn \int_if_odd:n #1 { p , T , F , TF}
{
\if_int_odd:w \@@_eval:w #1 \@@_eval_end:
@@ -1732,8 +1694,6 @@
\prg_return_false:
\fi:
}
-\__kernel_patch_conditional_args:nNNpnn
- { { \__kernel_chk_expr:nNnN {#1} \@@_eval:w { } \int_if_even:n } }
\prg_new_conditional:Npnn \int_if_even:n #1 { p , T , F , TF}
{
\reverse_if:N \if_int_odd:w \@@_eval:w #1 \@@_eval_end:
@@ -1851,21 +1811,6 @@
% step size of zero before checking the sign, but we optimize for the
% most frequent case (positive step).
% \begin{macrocode}
-\__kernel_patch_args:nNNpn
- {
- {
- \__kernel_chk_expr:nNnN {#1} \@@_eval:w { }
- \int_step_function:nnnN
- }
- {
- \__kernel_chk_expr:nNnN {#2} \@@_eval:w { }
- \int_step_function:nnnN
- }
- {
- \__kernel_chk_expr:nNnN {#3} \@@_eval:w { }
- \int_step_function:nnnN
- }
- }
\cs_new:Npn \int_step_function:nnnN #1#2#3
{
\exp_after:wN \@@_step:wwwN
@@ -2594,6 +2539,17 @@
% \end{variable}
% \end{variable}
%
+% \subsection{Integers for earlier modules}
+%
+%<@@=seq>
+%
+% \begin{variable}{\l_@@_internal_a_int, \l_@@_internal_b_int}
+% \begin{macrocode}
+\int_new:N \l_@@_internal_a_int
+\int_new:N \l_@@_internal_b_int
+% \end{macrocode}
+% \end{variable}
+%
% \begin{macrocode}
%</initex|package>
% \end{macrocode}