From 932716f98734dec3d6502355f5618e5895729499 Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sun, 20 Mar 2022 03:00:57 +0000 Subject: CTAN sync 202203200300 --- macros/latex/contrib/functional/functional.sty | 1334 +++++++++++++++++++++--- 1 file changed, 1170 insertions(+), 164 deletions(-) (limited to 'macros/latex/contrib/functional/functional.sty') diff --git a/macros/latex/contrib/functional/functional.sty b/macros/latex/contrib/functional/functional.sty index 95e5ada3dc..dcc863b3c5 100644 --- a/macros/latex/contrib/functional/functional.sty +++ b/macros/latex/contrib/functional/functional.sty @@ -1,22 +1,24 @@ %%% -*- coding: utf-8 -*- %% ---------------------------------------------------------------------------- -%% Functional: LaTeX2 functional interfaces to LaTeX3 programming layer +%% Functional: LaTeX2 functional interfaces for LaTeX3 programming layer %% Copyright : 2022 (c) Jianrui Lyu %% Repository: https://github.com/lvjr/functional +%% Repository: https://bitbucket.org/lvjr/functional %% License : The LaTeX Project Public License 1.3c %% ---------------------------------------------------------------------------- %%% -------------------------------------------------------- -%%> \section{Interfaces for Function Definitions (l3basics)} +%%> \section{Interfaces for Functional Programming (Prg)} %%% -------------------------------------------------------- \NeedsTeXFormat{LaTeX2e}[2018-04-01] \RequirePackage{expl3} -\ProvidesExplPackage{functional}{2022-03-10}{2022A} - {^^JLaTeX2 functional interfaces to LaTeX3 programming layer} +\ProvidesExplPackage{functional}{2022-03-19}{2022B} + {^^JLaTeX2 functional interfaces for LaTeX3 programming layer} \cs_generate_variant:Nn \iow_log:n { V } +\cs_generate_variant:Nn \tl_log:n { e } \cs_generate_variant:Nn \tl_set:Nn { Ne } \tl_new:N \gResultTl @@ -51,16 +53,6 @@ \tl_const:Nn \c__fun_parameter_called_vii_tl { {#7} } \tl_const:Nn \c__fun_parameter_called_viii_tl { {#8} } \tl_const:Nn \c__fun_parameter_called_ix_tl { {#9} } -\tl_new:N \l__fun_argument_tl -\tl_new:N \l__fun_argument_i_tl -\tl_new:N \l__fun_argument_ii_tl -\tl_new:N \l__fun_argument_iii_tl -\tl_new:N \l__fun_argument_iv_tl -\tl_new:N \l__fun_argument_v_tl -\tl_new:N \l__fun_argument_vi_tl -\tl_new:N \l__fun_argument_vii_tl -\tl_new:N \l__fun_argument_viii_tl -\tl_new:N \l__fun_argument_ix_tl %% #1: function name; #2: argument specification; #3 function body \cs_new_protected:Npn \__fun_new_function:Nnn #1 #2 #3 @@ -113,13 +105,18 @@ \cs_set_eq:NN \PrgNewConditional \__fun_new_conditional:Nnn +\int_new:N \g__fun_nesting_level_int + %% #1: function name; #2: argument specifications; #3 parameters tl defined %% Some times we need to create a function without arguments \cs_new_protected:Npn \__fun_new_with_arg_:Nnn #1 #2 #3 { \cs_new_protected:Npn #1 #3 { + \int_gincr:N \g__fun_nesting_level_int \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_:Nnn { NnV } @@ -129,8 +126,11 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_i:Nnn { NnV } @@ -140,9 +140,12 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_ii:Nnn { NnV } @@ -152,10 +155,13 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } - \tl_set:Nn \l__fun_argument_iii_tl { ##3 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } + \__fun_one_argument_gset:nn { 3 } { ##3 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_iii:Nnn { NnV } @@ -165,11 +171,14 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } - \tl_set:Nn \l__fun_argument_iii_tl { ##3 } - \tl_set:Nn \l__fun_argument_iv_tl { ##4 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } + \__fun_one_argument_gset:nn { 3 } { ##3 } + \__fun_one_argument_gset:nn { 4 } { ##4 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_iv:Nnn { NnV } @@ -179,12 +188,15 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } - \tl_set:Nn \l__fun_argument_iii_tl { ##3 } - \tl_set:Nn \l__fun_argument_iv_tl { ##4 } - \tl_set:Nn \l__fun_argument_v_tl { ##5 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } + \__fun_one_argument_gset:nn { 3 } { ##3 } + \__fun_one_argument_gset:nn { 4 } { ##4 } + \__fun_one_argument_gset:nn { 5 } { ##5 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_v:Nnn { NnV } @@ -194,13 +206,16 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } - \tl_set:Nn \l__fun_argument_iii_tl { ##3 } - \tl_set:Nn \l__fun_argument_iv_tl { ##4 } - \tl_set:Nn \l__fun_argument_v_tl { ##5 } - \tl_set:Nn \l__fun_argument_vi_tl { ##6 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } + \__fun_one_argument_gset:nn { 3 } { ##3 } + \__fun_one_argument_gset:nn { 4 } { ##4 } + \__fun_one_argument_gset:nn { 5 } { ##5 } + \__fun_one_argument_gset:nn { 6 } { ##6 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_vi:Nnn { NnV } @@ -210,14 +225,17 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } - \tl_set:Nn \l__fun_argument_iii_tl { ##3 } - \tl_set:Nn \l__fun_argument_iv_tl { ##4 } - \tl_set:Nn \l__fun_argument_v_tl { ##5 } - \tl_set:Nn \l__fun_argument_vi_tl { ##6 } - \tl_set:Nn \l__fun_argument_vii_tl { ##7 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } + \__fun_one_argument_gset:nn { 3 } { ##3 } + \__fun_one_argument_gset:nn { 4 } { ##4 } + \__fun_one_argument_gset:nn { 5 } { ##5 } + \__fun_one_argument_gset:nn { 6 } { ##6 } + \__fun_one_argument_gset:nn { 7 } { ##7 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_vii:Nnn { NnV } @@ -227,15 +245,18 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } - \tl_set:Nn \l__fun_argument_iii_tl { ##3 } - \tl_set:Nn \l__fun_argument_iv_tl { ##4 } - \tl_set:Nn \l__fun_argument_v_tl { ##5 } - \tl_set:Nn \l__fun_argument_vi_tl { ##6 } - \tl_set:Nn \l__fun_argument_vii_tl { ##7 } - \tl_set:Nn \l__fun_argument_viii_tl { ##8 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } + \__fun_one_argument_gset:nn { 3 } { ##3 } + \__fun_one_argument_gset:nn { 4 } { ##4 } + \__fun_one_argument_gset:nn { 5 } { ##5 } + \__fun_one_argument_gset:nn { 6 } { ##6 } + \__fun_one_argument_gset:nn { 7 } { ##7 } + \__fun_one_argument_gset:nn { 8 } { ##8 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_viii:Nnn { NnV } @@ -245,39 +266,39 @@ { \cs_new_protected:Npn #1 #3 { - \tl_set:Nn \l__fun_argument_i_tl { ##1 } - \tl_set:Nn \l__fun_argument_ii_tl { ##2 } - \tl_set:Nn \l__fun_argument_iii_tl { ##3 } - \tl_set:Nn \l__fun_argument_iv_tl { ##4 } - \tl_set:Nn \l__fun_argument_v_tl { ##5 } - \tl_set:Nn \l__fun_argument_vi_tl { ##6 } - \tl_set:Nn \l__fun_argument_vii_tl { ##7 } - \tl_set:Nn \l__fun_argument_viii_tl { ##8 } - \tl_set:Nn \l__fun_argument_ix_tl { ##9 } + \int_gincr:N \g__fun_nesting_level_int + \__fun_one_argument_gset:nn { 1 } { ##1 } + \__fun_one_argument_gset:nn { 2 } { ##2 } + \__fun_one_argument_gset:nn { 3 } { ##3 } + \__fun_one_argument_gset:nn { 4 } { ##4 } + \__fun_one_argument_gset:nn { 5 } { ##5 } + \__fun_one_argument_gset:nn { 6 } { ##6 } + \__fun_one_argument_gset:nn { 7 } { ##7 } + \__fun_one_argument_gset:nn { 8 } { ##8 } + \__fun_one_argument_gset:nn { 9 } { ##9 } \__fun_evaluate:Nn #1 {#2} + \int_gdecr:N \g__fun_nesting_level_int + \__fun_return_result: } } \cs_generate_variant:Nn \__fun_new_with_arg_ix:Nnn { NnV } -\int_new:N \g__fun_nesting_level_int -\int_new:N \l__fun_argtype_number_int \tl_new:N \l__fun_argtype_tl \tl_const:Nn \c__fun_argtype_m_tl { m } \tl_const:Nn \c__fun_argtype_M_tl { M } \tl_const:Nn \c__fun_argtype_n_tl { n } \tl_const:Nn \c__fun_argtype_N_tl { N } +\tl_new:N \l__fun_argument_tl %% #1: function name; #2: argument specifications \cs_new_protected:Npn \__fun_evaluate:Nn #1 #2 { - \int_zero:N \l__fun_argtype_number_int - \int_gincr:N \g__fun_nesting_level_int + \__fun_argtype_index_gzero: \__fun_arguments_gclear: \tl_map_variable:nNn { #2 } \l__fun_argtype_tl % spaces are ignored { - \int_incr:N \l__fun_argtype_number_int - \tl_set_eq:Nc \l__fun_argument_tl - { l__fun_argument_ \int_to_roman:n { \l__fun_argtype_number_int } _tl } + \__fun_argtype_index_gincr: + \__fun_one_argument_get:eN { \__fun_argtype_index_use: } \l__fun_argument_tl \tl_case:Nn \l__fun_argtype_tl { \c__fun_argtype_m_tl @@ -300,19 +321,14 @@ } \__fun_arguments_log:N #1 \__fun_arguments_called:c { __fun_defined_ \cs_to_str:N #1 : w } - \int_gdecr:N \g__fun_nesting_level_int - \__fun_return_result: } -\cs_set_eq:NN \__fun_cs_temp:w \scan_stop: - \cs_new_protected:Npn \__fun_evaluate_and_put_argument:N #1 { - \cs_set_eq:Nc \__fun_cs_temp:w + \cs_if_exist:cTF { __fun_defined_ \exp_last_unbraced:Ne \cs_to_str:N { \tl_head:N #1 } : w } - \cs_if_exist:NTF \__fun_cs_temp:w { #1 \__fun_arguments_gput:e { { \exp_not:V \gResultTl } } @@ -322,6 +338,57 @@ } } +%% #1: argument number; #2: token lists +\cs_new_protected:Npn \__fun_one_argument_gset:nn #1 #2 + { + \tl_gset:cn + { g__fun_one_argument_ \int_use:N \g__fun_nesting_level_int _#1_tl } { #2 } + %\__fun_one_argument_log:nn { #1 } { set } + } + +%% #1: argument number; #2: variable of token lists +\cs_new_protected:Npn \__fun_one_argument_get:nN #1 #2 + { + \tl_set_eq:Nc + #2 { g__fun_one_argument_ \int_use:N \g__fun_nesting_level_int _ #1 _tl } + %\__fun_one_argument_log:nn { #1 } { get } + } +\cs_generate_variant:Nn \__fun_one_argument_get:nN { eN } + +%% #1: argument number; #2: get or set +\cs_new_protected:Npn \__fun_one_argument_log:nn #1 #2 + { + \tl_log:e + { + #2 ~ level _ \int_use:N \g__fun_nesting_level_int _ arg _ #1 ~ = ~ + \exp_not:v + { g__fun_one_argument_ \int_use:N \g__fun_nesting_level_int _#1_tl } + } + } + +\int_new:c { g__fun_argtype_index_ 1 _int } +\int_new:c { g__fun_argtype_index_ 2 _int } +\int_new:c { g__fun_argtype_index_ 3 _int } +\int_new:c { g__fun_argtype_index_ 4 _int } +\int_new:c { g__fun_argtype_index_ 5 _int } + +\cs_new_protected:Npn \__fun_argtype_index_gzero: + { + \int_gzero_new:c + { g__fun_argtype_index_ \int_use:N \g__fun_nesting_level_int _int } + } + +\cs_new_protected:Npn \__fun_argtype_index_gincr: + { + \int_gincr:c + { g__fun_argtype_index_ \int_use:N \g__fun_nesting_level_int _int } + } + +\cs_new:Npn \__fun_argtype_index_use: + { + \int_use:c { g__fun_argtype_index_ \int_use:N \g__fun_nesting_level_int _int } + } + \cs_new_protected:Npn \__fun_arguments_called:N #1 { \exp_last_unbraced:Nv @@ -350,6 +417,12 @@ } \cs_generate_variant:Nn \__fun_arguments_gput:n { e } +\cs_set_eq:NN \Break \prg_break: +\cs_set_eq:NN \PrgBreak \prg_break: + +\cs_set_eq:NN \BreakDo \prg_break:n +\cs_set_eq:NN \PrgBreakDo \prg_break:n + \cs_new_protected:Npn \__fun_put_result:n #1 { \tl_gput_right:Nn \gResultTl { #1 } @@ -361,27 +434,6 @@ \__fun_put_result:n { #1 } } -\PrgNewFunction \Name { m } - { - \exp_args:Nc \__fun_put_result:n { #1 } - } -\cs_set_eq:NN \UseName \Name - -\PrgNewFunction \Expand { m } - { - \__fun_put_result:e { #1 } - } -\cs_set_eq:NN \UseExpand \Expand - -\PrgNewFunction \Value { M } - { - \__fun_put_result:V #1 - } -\cs_set_eq:NN \UseValue \Value - -\cs_set_eq:NN \ExpNot \exp_not:n -\cs_set_eq:NN \ExpValue \exp_not:V - \cs_new_protected:Npn \__fun_return_result: { \int_compare:nNnT { \g__fun_nesting_level_int } = { 0 } @@ -484,28 +536,50 @@ \Functional { scoping = false, tracing = false } -\PrgNewFunction \UseOne { n } +\cs_new_protected:Npn \__fun_ignore_spaces_on: { - \Result { #1 } + \ExplSyntaxOn + \char_set_catcode_math_subscript:N \_ + \char_set_catcode_other:N \: } +\cs_set_eq:NN \IgnoreSpacesOn \__fun_ignore_spaces_on: +\cs_set_eq:NN \IgnoreSpacesOff \ExplSyntaxOff + +%%% -------------------------------------------------------- +%%> \section{Interfaces for Argument Using (Use)} +%%% -------------------------------------------------------- -\PrgNewFunction \GobbleOne { n } +\PrgNewFunction \Name { m } { - \Result { } + \exp_args:Nc \__fun_put_result:n { #1 } } +\cs_set_eq:NN \UseName \Name -\PrgNewFunction \UseGobble { n n } +\PrgNewFunction \Value { M } { - \UseOne { #1 } + \__fun_put_result:V #1 } +\cs_set_eq:NN \UseValue \Value -\PrgNewFunction \GobbleUse { n n } +\PrgNewFunction \Expand { m } { - \UseOne { #2 } + \__fun_put_result:e { #1 } } +\cs_set_eq:NN \UseExpand \Expand + +\cs_set_eq:NN \ExpNot \exp_not:n +\cs_set_eq:NN \ExpValue \exp_not:V + +\PrgNewFunction \UseOne { n } { \Result { #1 } } + +\PrgNewFunction \GobbleOne { n } { \Result { } } + +\PrgNewFunction \UseGobble { n n } { \UseOne { #1 } } + +\PrgNewFunction \GobbleUse { n n } { \UseOne { #2 } } %%% -------------------------------------------------------- -%%> \section{Interfaces for Control Structures (l3prg)} +%%> \section{Interfaces for Control Structures (Bool)} %%% -------------------------------------------------------- \bool_const:Nn \cTrueBool { \c_true_bool } @@ -519,8 +593,14 @@ \bool_new:N \gTmpiBool \bool_new:N \gTmpjBool \bool_new:N \gTmpkBool \bool_new:N \g@Funx@Bool \bool_new:N \g@Funy@Bool \bool_new:N \g@Funz@Bool -\cs_set_eq:NN \BoolNew \bool_new:N -\cs_set_eq:NN \BoolLog \bool_log:N +\PrgNewFunction \BoolNew { M } { \bool_new:N #1 } + +\PrgNewFunction \BoolConst { M m } { \bool_const:Nn #1 { #2 } } + +\PrgNewFunction \BoolSet { M m } { + \__fun_do_assignment:Nnn #1 + { \bool_gset:Nn #1 { #2 } } { \bool_set:Nn #1 { #2 } } +} \PrgNewFunction \BoolSetTrue { M } { @@ -532,15 +612,59 @@ \__fun_do_assignment:Nnn #1 { \bool_gset_false:N #1 } { \bool_set_false:N #1 } } -\PrgNewConditional \BoolIf { N } +\PrgNewFunction \BoolSetEq { M M } + { + \__fun_do_assignment:Nnn #1 + { \bool_gset_eq:NN #1 #2 } { \bool_set_eq:NN #1 #2 } + } + +\PrgNewFunction \BoolLog { m } { \bool_log:n { #1 } } + +\PrgNewFunction \BoolVarLog { M } { \bool_log:N #1 } + +\PrgNewFunction \BoolShow { m } { \bool_show:n { #1 } } + +\PrgNewFunction \BoolVarShow { M } { \bool_show:N #1 } + +\PrgNewConditional \BoolIfExist { M } + { + \bool_if_exist:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \BoolVarIf { M } { \Result { #1 } } + +\PrgNewConditional \BoolVarNot { M } + { + \bool_if:NTF #1 + { \Result { \cFalseBool } } { \Result { \cTrueBool } } + } + +\PrgNewConditional \BoolVarAnd { M M } + { + \bool_lazy_and:nnTF {#1} {#2} + { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \BoolVarOr { M M } + { + \bool_lazy_or:nnTF {#1} {#2} + { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \BoolVarXor { M M } { - \Result { #1 } + \bool_xor:nnTF {#1} {#2} + { \Result { \cTrueBool } } { \Result { \cFalseBool } } } %%% -------------------------------------------------------- -%%> \section{Interfaces for Token Lists (l3tl)} +%%> \section{Interfaces for Token Lists (Tl)} %%% -------------------------------------------------------- +\tl_set_eq:NN \cEmptyTl \c_empty_tl +\tl_set_eq:NN \cSpaceTl \c_space_tl +\tl_set_eq:NN \cNoValueTl \c_novalue_tl + \tl_new:N \lTmpaTl \tl_new:N \lTmpbTl \tl_new:N \lTmpcTl \tl_new:N \lTmpiTl \tl_new:N \lTmpjTl \tl_new:N \lTmpkTl \tl_new:N \l@Funx@Tl \tl_new:N \l@Funy@Tl \tl_new:N \l@Funz@Tl @@ -549,17 +673,48 @@ \tl_new:N \gTmpiTl \tl_new:N \gTmpjTl \tl_new:N \gTmpkTl \tl_new:N \g@Funx@Tl \tl_new:N \g@Funy@Tl \tl_new:N \g@Funz@Tl -\cs_set_eq:NN \TlNew \tl_new:N -\cs_set_eq:NN \TlLog \tl_log:N +\PrgNewFunction \TlNew { M } { \tl_new:N #1 } + +\PrgNewFunction \TlLog { m } { \tl_log:n { #1 } } + +\PrgNewFunction \TlVarLog { M } { \tl_log:N #1 } + +\PrgNewFunction \TlShow { m } { \tl_show:n { #1 } } + +\PrgNewFunction \TlVarShow { M } { \tl_show:N #1 } + +\PrgNewFunction \TlUse { M } { \Result { \Value #1 } } + +\PrgNewFunction \TlToStr { m } { \Expand { \tl_to_str:n { #1 } } } + +\PrgNewFunction \TlVarToStr { M } { \Expand { \tl_to_str:N #1 } } + +\PrgNewFunction \TlConst { M m } { \tl_const:Nn #1 { #2 } } + +\PrgNewFunction \TlSet { M m } + { + \__fun_do_assignment:Nnn #1 { \tl_gset:Nn #1 {#2} } { \tl_set:Nn #1 {#2} } + } + +\PrgNewFunction \TlSetEq { M M } + { + \__fun_do_assignment:Nnn #1 { \tl_gset_eq:NN #1 #2 } { \tl_set_eq:NN #1 #2 } + } + +\PrgNewFunction \TlConcat { M M M } + { + \__fun_do_assignment:Nnn #1 + { \tl_gconcat:NNN #1 #2 #3 } { \tl_concat:NNN #1 #2 #3 } + } \PrgNewFunction \TlClear { M } { \__fun_do_assignment:Nnn #1 { \tl_gclear:N #1 } { \tl_clear:N #1 } } -\PrgNewFunction \TlSet { M m } +\PrgNewFunction \TlClearNew { M } { - \__fun_do_assignment:Nnn #1 { \tl_gset:Nn #1 {#2} } { \tl_set:Nn #1 {#2} } + \__fun_do_assignment:Nnn #1 { \tl_gclear_new:N #1 } { \tl_clear_new:N #1 } } \PrgNewFunction \TlPutLeft { M m } @@ -574,113 +729,964 @@ { \tl_gput_right:Nn #1 {#2} } { \tl_put_right:Nn #1 {#2} } } -\PrgNewFunction \TlUse { M } +\PrgNewFunction \TlReplaceOnce { M m m } { - \Result { \Value #1 } + \__fun_do_assignment:Nnn #1 + { \tl_greplace_once:Nnn #1 {#2} {#3} } { \tl_replace_once:Nnn #1 {#2} {#3} } } -\PrgNewConditional \TlIfEmpty { N } +\PrgNewFunction \TlReplaceAll { M m m } { - \tl_if_empty:NTF #1 - { \Result { \cTrueBool } } - { \Result { \cFalseBool } } + \__fun_do_assignment:Nnn #1 + { \tl_greplace_all:Nnn #1 {#2} {#3} } { \tl_replace_all:Nnn #1 {#2} {#3} } } -\PrgNewConditional \TlIfEq { N N } +\PrgNewFunction \TlRemoveOnce { M m } { - \tl_if_eq:NNTF #1 #2 - { \Result { \cTrueBool } } - { \Result { \cFalseBool } } + \__fun_do_assignment:Nnn #1 + { \tl_gremove_once:Nn #1 {#2} } { \tl_remove_once:Nn #1 {#2} } + } + +\PrgNewFunction \TlRemoveAll { M m } + { + \__fun_do_assignment:Nnn #1 + { \tl_gremove_all:Nn #1 {#2} } { \tl_remove_all:Nn #1 {#2} } + } + +\PrgNewFunction \TlTrimSpaces { m } { \Expand { \tl_trim_spaces:n { #1 } } } + +\PrgNewFunction \TlVarTrimSpaces { M } + { + \__fun_do_assignment:Nnn #1 { \tl_gtrim_spaces:N #1 } { \tl_trim_spaces:N #1 } + } + +\PrgNewFunction \TlCount { m } { \Expand { \tl_count:n { #1 } } } + +\PrgNewFunction \TlVarCount { M } { \Expand { \tl_count:N #1 } } + +\PrgNewFunction \TlHead { m } { \Expand { \tl_head:n { #1 } } } + +\PrgNewFunction \TlVarHead { M } { \Expand { \tl_head:N #1 } } + +\PrgNewFunction \TlTail { m } { \Expand { \tl_tail:n { #1 } } } + +\PrgNewFunction \TlVarTail { M } { \Expand { \tl_tail:N #1 } } + +\PrgNewFunction \TlItem { m m } { \Expand { \tl_item:nn {#1} {#2} } } + +\PrgNewFunction \TlVarItem { M m } { \Expand { \tl_item:Nn #1 {#2} } } + +\PrgNewFunction \TlRandItem { m } { \Expand { \tl_rand_item:n {#1} } } + +\PrgNewFunction \TlVarRandItem { M } { \Expand { \tl_rand_item:N #1 } } + +\PrgNewFunction \TlVarCase { M m } { \tl_case:Nn {#1} {#2} } +\PrgNewFunction \TlVarCaseT { M m n } { \tl_case:NnT {#1} {#2} {#3} } +\PrgNewFunction \TlVarCaseF { M m n } { \tl_case:NnF {#1} {#2} {#3} } +\PrgNewFunction \TlVarCaseTF { M m n n } { \tl_case:NnTF {#1} {#2} {#3} {#4} } + +\PrgNewFunction \TlMapInline { m n } + { + \tl_map_inline:nn {#1} {#2} + } + +\PrgNewFunction \TlVarMapInline { M n } + { + \tl_map_inline:Nn #1 {#2} + } + +\PrgNewFunction \TlMapVariable { m M n } + { + \tl_map_variable:nNn {#1} #2 {#3} + } + +\PrgNewFunction \TlVarMapVariable { M M n } + { + \tl_map_variable:NNn #1 #2 {#3} + } + +\PrgNewConditional \TlIfExist { M } + { + \tl_if_exist:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlIfEmpty { m } + { + \tl_if_empty:nTF {#1} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlVarIfEmpty { M } + { + \tl_if_empty:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlIfBlank { m } + { + \tl_if_blank:nTF {#1} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlIfEq { m m } + { + \tl_if_eq:nnTF {#1} {#2} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlVarIfEq { M M } + { + \tl_if_eq:NNTF #1 #2 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlIfIn { m m } + { + \tl_if_in:nnTF {#1} {#2} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlVarIfIn { M m } + { + \tl_if_in:NnTF #1 {#2} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlIfSingle { m } + { + \tl_if_single:nTF {#1} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \TlVarIfSingle { M } + { + \tl_if_single:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } } %%% -------------------------------------------------------- -%%> \section{Interfaces for Integers (l3int)} +%%> \section{Interfaces for Strings (Str)} %%% -------------------------------------------------------- -\int_new:N \lTmpaInt \int_new:N \lTmpbInt \int_new:N \lTmpcInt -\int_new:N \lTmpiInt \int_new:N \lTmpjInt \int_new:N \lTmpkInt -\int_new:N \l@Funx@Int \int_new:N \l@Funy@Int \int_new:N \l@Funz@Int +\str_set_eq:NN \cAmpersandStr \c_ampersand_str +\str_set_eq:NN \cAttignStr \c_atsign_str +\str_set_eq:NN \cBackslashStr \c_backslash_str +\str_set_eq:NN \cLeftBraceStr \c_left_brace_str +\str_set_eq:NN \cRightBraceStr \c_right_brace_str +\str_set_eq:NN \cCircumflexStr \c_circumflex_str +\str_set_eq:NN \cColonStr \c_colon_str +\str_set_eq:NN \cDollarStr \c_dollar_str +\str_set_eq:NN \cHashStr \c_hash_str +\str_set_eq:NN \cPercentStr \c_percent_str +\str_set_eq:NN \cTildeStr \c_tilde_str +\str_set_eq:NN \cUnderscoreStr \c_underscore_str +\str_set_eq:NN \cZeroStr \c_zero_str -\int_new:N \gTmpaInt \int_new:N \gTmpbInt \int_new:N \gTmpcInt -\int_new:N \gTmpiInt \int_new:N \gTmpjInt \int_new:N \gTmpkInt -\int_new:N \g@Funx@Int \int_new:N \g@Funy@Int \int_new:N \g@Funz@Int +\str_new:N \lTmpaStr \str_new:N \lTmpbStr \str_new:N \lTmpcStr +\str_new:N \lTmpiStr \str_new:N \lTmpjStr \str_new:N \lTmpkStr +\str_new:N \l@Funx@Str \str_new:N \l@Funy@Str \str_new:N \l@Funz@Str -\cs_set_eq:NN \IntNew \int_new:N -\cs_set_eq:NN \IntLog \int_log:N +\str_new:N \gTmpaStr \str_new:N \gTmpbStr \str_new:N \gTmpcStr +\str_new:N \gTmpiStr \str_new:N \gTmpjStr \str_new:N \gTmpkStr +\str_new:N \g@Funx@Str \str_new:N \g@Funy@Str \str_new:N \g@Funz@Str -\PrgNewFunction \IntZero { M } +\PrgNewFunction \StrNew { M } { \str_new:N #1 } + +\PrgNewFunction \StrLog { m } { \str_log:n { #1 } } + +\PrgNewFunction \StrVarLog { M } { \str_log:N #1 } + +\PrgNewFunction \StrShow { m } { \str_show:n { #1 } } + +\PrgNewFunction \StrVarShow { M } { \str_show:N #1 } + +\PrgNewFunction \StrUse { M } { \Result { \Value #1 } } + +\PrgNewFunction \StrConst { M m } { \str_const:Nn #1 {#2} } + +\PrgNewFunction \StrSet { M m } { - \__fun_do_assignment:Nnn #1 { \int_gzero:N #1 } { \int_zero:N #1 } + \__fun_do_assignment:Nnn #1 { \str_gset:Nn #1 {#2} } { \str_set:Nn #1 {#2} } } -\PrgNewFunction \IntIncr { M } +\PrgNewFunction \StrSetEq { M M } { - \__fun_do_assignment:Nnn #1 { \int_gincr:N #1 } { \int_incr:N #1 } + \__fun_do_assignment:Nnn #1 { \str_gset_eq:NN #1 #2 } { \str_set_eq:NN #1 #2 } } -\PrgNewFunction \IntDecr { M } +\PrgNewFunction \StrConcat { M M M } { - \__fun_do_assignment:Nnn #1 { \int_gdecr:N #1 } { \int_decr:N #1 } + \__fun_do_assignment:Nnn #1 + { \str_gconcat:NNN #1 #2 #3 } { \str_concat:NNN #1 #2 #3 } } -\PrgNewFunction \IntSet { M m } +\PrgNewFunction \StrClear { M } { - \__fun_do_assignment:Nnn #1 { \int_gset:Nn #1 {#2} } { \int_set:Nn #1 {#2} } + \__fun_do_assignment:Nnn #1 { \str_gclear:N #1 } { \str_clear:N #1 } } -\PrgNewFunction \IntAdd { M m } +\PrgNewFunction \StrClearNew { M } { - \__fun_do_assignment:Nnn #1 { \int_gadd:Nn #1 {#2} } { \int_add:Nn #1 {#2} } + \__fun_do_assignment:Nnn #1 { \str_gclear_new:N #1 } { \str_clear_new:N #1 } } -\PrgNewFunction \IntSub { M m } +\PrgNewFunction \StrPutLeft { M m } { - \__fun_do_assignment:Nnn #1 { \int_gsub:Nn #1 {#2} } { \int_sub:Nn #1 {#2} } + \__fun_do_assignment:Nnn #1 + { \str_gput_left:Nn #1 {#2} } { \str_put_left:Nn #1 {#2} } } -\PrgNewFunction \IntUse { M } +\PrgNewFunction \StrPutRight { M m } { - \Result { \Value #1 } + \__fun_do_assignment:Nnn #1 + { \str_gput_right:Nn #1 {#2} } { \str_put_right:Nn #1 {#2} } } -\PrgNewFunction \IntEval { m } +\PrgNewFunction \StrReplaceOnce { M m m } { - \Result { \Expand { \int_eval:n { #1 } } } + \__fun_do_assignment:Nnn #1 + { \str_greplace_once:Nnn #1 {#2} {#3} } { \str_replace_once:Nnn #1 {#2} {#3} } } -\PrgNewFunction \IntMathAdd { m m } +\PrgNewFunction \StrReplaceAll { M m m } { - \int_set:Nn \l@Funx@Int { \int_eval:n { #1 + #2 } } - \Result { \Value \l@Funx@Int } + \__fun_do_assignment:Nnn #1 + { \str_greplace_all:Nnn #1 {#2} {#3} } { \str_replace_all:Nnn #1 {#2} {#3} } } -\PrgNewFunction \IntMathSub { m m } +\PrgNewFunction \StrRemoveOnce { M m } { - \int_set:Nn \l@Funx@Int { \int_eval:n { #1 - #2 } } - \Result { \Value \l@Funx@Int } + \__fun_do_assignment:Nnn #1 + { \str_gremove_once:Nn #1 {#2} } { \str_remove_once:Nn #1 {#2} } } -\PrgNewFunction \IntMathMult { m m } +\PrgNewFunction \StrRemoveAll { M m } { - \int_set:Nn \l@Funx@Int { \int_eval:n { #1 * #2 } } - \Result { \Value \l@Funx@Int } + \__fun_do_assignment:Nnn #1 + { \str_gremove_all:Nn #1 {#2} } { \str_remove_all:Nn #1 {#2} } } -\PrgNewFunction \IntMathDiv { m m } +%% Avoid naming confict with xstring package +\cs_if_exist:NF \StrCount + { \PrgNewFunction \StrCount { m } { \Expand { \str_count:n { #1 } } } } + +%% Provide another name for \StrCount function +\PrgNewFunction \StrSize { m } { \Expand { \str_count:n { #1 } } } + +\PrgNewFunction \StrVarCount { M } { \Expand { \str_count:N #1 } } + +\PrgNewFunction \StrHead { m } { \Expand { \str_head:n { #1 } } } + +\PrgNewFunction \StrVarHead { M } { \Expand { \str_head:N #1 } } + +\PrgNewFunction \StrTail { m } { \Expand { \str_tail:n { #1 } } } + +\PrgNewFunction \StrVarTail { M } { \Expand { \str_tail:N #1 } } + +\PrgNewFunction \StrItem { m m } { \Expand { \str_item:nn {#1} {#2} } } + +\PrgNewFunction \StrVarItem { M m } { \Expand { \str_item:Nn #1 {#2} } } + +\PrgNewFunction \StrCase { m m } { \str_case:nn {#1} {#2} } +\PrgNewFunction \StrCaseT { m m n } { \str_case:nnT {#1} {#2} {#3} } +\PrgNewFunction \StrCaseF { m m n } { \str_case:nnF {#1} {#2} {#3} } +\PrgNewFunction \StrCaseTF { m m n n } { \str_case:nnTF {#1} {#2} {#3} {#4} } + +\PrgNewFunction \StrMapInline { m n } { - \int_set:Nn \l@Funx@Int { \int_eval:n { #1 / #2 } } - \Result { \Value \l@Funx@Int } + \str_map_inline:nn {#1} {#2} } -\PrgNewFunction \IntStepVariable { m m m M n } +\PrgNewFunction \StrVarMapInline { M n } { - \int_step_variable:nnnNn { #1 } { #2 } { #3 } #4 { #5 } + \str_map_inline:Nn #1 {#2} } -\PrgNewConditional \IntCompare { m N m } +\PrgNewFunction \StrMapVariable { m M n } { - \int_compare:nNnTF {#1} #2 {#3} - { \Result { \cTrueBool } } - { \Result { \cFalseBool } } + \str_map_variable:nNn {#1} #2 {#3} + } + +\PrgNewFunction \StrVarMapVariable { M M n } + { + \str_map_variable:NNn #1 #2 {#3} + } + +\PrgNewConditional \StrIfExist { M } + { + \str_if_exist:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \StrVarIfEmpty { M } + { + \str_if_empty:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \StrIfEq { m m } + { + \str_if_eq:nnTF {#1} {#2} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \StrVarIfEq { M M } + { + \str_if_eq:NNTF #1 #2 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \StrIfIn { m m } + { + \str_if_in:nnTF {#1} {#2} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \StrVarIfIn { M m } + { + \str_if_in:NnTF #1 {#2} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +%% Avoid naming confict with xstring package +\cs_if_exist:NF \StrCompare + { + \PrgNewConditional \StrCompare { m N m } + { + \str_compare:nNnTF {#1} #2 {#3} + { \Result { \cTrueBool } } + { \Result { \cFalseBool } } + } + } + +%% Provide another name for \StrCompare function +\PrgNewConditional \StrIfCompare { m N m } + { + \str_compare:nNnTF {#1} #2 {#3} + { \Result { \cTrueBool } } + { \Result { \cFalseBool } } + } + +%%% -------------------------------------------------------- +%%> \section{Interfaces for Integers (Int)} +%%% -------------------------------------------------------- + +\cs_set_eq:NN \cZeroInt \c_zero_int +\cs_set_eq:NN \cOneInt \c_one_int +\cs_set_eq:NN \cMaxInt \c_max_int +\cs_set_eq:NN \cMaxRegisterInt \c_max_register_int +\cs_set_eq:NN \cMaxCharInt \c_max_char_in + +\int_new:N \lTmpaInt \int_new:N \lTmpbInt \int_new:N \lTmpcInt +\int_new:N \lTmpiInt \int_new:N \lTmpjInt \int_new:N \lTmpkInt +\int_new:N \l@Funx@Int \int_new:N \l@Funy@Int \int_new:N \l@Funz@Int + +\int_new:N \gTmpaInt \int_new:N \gTmpbInt \int_new:N \gTmpcInt +\int_new:N \gTmpiInt \int_new:N \gTmpjInt \int_new:N \gTmpkInt +\int_new:N \g@Funx@Int \int_new:N \g@Funy@Int \int_new:N \g@Funz@Int + +\PrgNewFunction \IntEval { m } + { + \Result { \Expand { \int_eval:n { #1 } } } + } + +\PrgNewFunction \IntMathAdd { m m } + { + \int_set:Nn \l@Funx@Int { \int_eval:n { (#1) + (#2) } } + \Result { \Value \l@Funx@Int } + } + +\PrgNewFunction \IntMathSub { m m } + { + \int_set:Nn \l@Funx@Int { \int_eval:n { (#1) - (#2) } } + \Result { \Value \l@Funx@Int } + } + +\PrgNewFunction \IntMathMult { m m } + { + \int_set:Nn \l@Funx@Int { \int_eval:n { (#1) * (#2) } } + \Result { \Value \l@Funx@Int } + } + +\PrgNewFunction \IntMathDiv { m m } + { + \Expand { \int_div_round:nn { #1 } { #2 } } + } + +\PrgNewFunction \IntMathDivTruncate { m m } + { + \Expand { \int_div_truncate:nn { #1 } { #2 } } + } + +\PrgNewFunction \IntMathSign { m } { \Expand { \int_sign:n { #1 } } } + +\PrgNewFunction \IntMathAbs { m } { \Expand { \int_abs:n { #1 } } } + +\PrgNewFunction \IntMathMax { m m } { \Expand { \int_max:nn { #1 } { #2 } } } + +\PrgNewFunction \IntMathMin { m m } { \Expand { \int_min:nn { #1 } { #2 } } } + +\PrgNewFunction \IntMathMod { m m } { \Expand { \int_mod:nn { #1 } { #2 } } } + +\PrgNewFunction \IntMathRand { m m } { \Expand { \int_rand:nn { #1 } { #2 } } } + +\PrgNewFunction \IntNew { M } { \int_new:N #1 } + +\PrgNewFunction \IntConst { M m } { \int_const:Nn #1 { #2 } } + +\PrgNewFunction \IntLog { m } { \int_log:n { #1 } } + +\PrgNewFunction \IntVarLog { M } { \int_log:N #1 } + +\PrgNewFunction \IntShow { m } { \int_show:n { #1 } } + +\PrgNewFunction \IntVarShow { M } { \int_show:N #1 } + +\PrgNewFunction \IntUse { M } { \Result { \Value #1 } } + +\PrgNewFunction \IntSet { M m } + { + \__fun_do_assignment:Nnn #1 { \int_gset:Nn #1 {#2} } { \int_set:Nn #1 {#2} } + } + +\PrgNewFunction \IntZero { M } + { + \__fun_do_assignment:Nnn #1 { \int_gzero:N #1 } { \int_zero:N #1 } + } + +\PrgNewFunction \IntZeroNew { M } + { + \__fun_do_assignment:Nnn #1 { \int_gzero_new:N #1 } { \int_zero_new:N #1 } + } + +\PrgNewFunction \IntSetEq { M M } + { + \__fun_do_assignment:Nnn #1 { \int_gset_eq:NN #1 #2 } { \int_set_eq:NN #1 #2 } + } + +\PrgNewFunction \IntIncr { M } + { + \__fun_do_assignment:Nnn #1 { \int_gincr:N #1 } { \int_incr:N #1 } + } + +\PrgNewFunction \IntDecr { M } + { + \__fun_do_assignment:Nnn #1 { \int_gdecr:N #1 } { \int_decr:N #1 } + } + +\PrgNewFunction \IntAdd { M m } + { + \__fun_do_assignment:Nnn #1 { \int_gadd:Nn #1 {#2} } { \int_add:Nn #1 {#2} } + } + +\PrgNewFunction \IntSub { M m } + { + \__fun_do_assignment:Nnn #1 { \int_gsub:Nn #1 {#2} } { \int_sub:Nn #1 {#2} } + } + +\PrgNewFunction \IntStepInline { m m m n } + { + \int_step_inline:nnnn { #1 } { #2 } { #3 } { #4 } + } + +\PrgNewFunction \IntStepVariable { m m m M n } + { + \int_step_variable:nnnNn { #1 } { #2 } { #3 } #4 { #5 } + } + +\PrgNewConditional \IntIfExist { M } + { + \int_if_exist:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \IntIfOdd { m } + { + \int_if_odd:nTF { #1 } { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \IntIfEven { m } + { + \int_if_even:nTF { #1 } { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \IntCompare { m N m } + { + \int_compare:nNnTF {#1} #2 {#3} + { \Result { \cTrueBool } } + { \Result { \cFalseBool } } + } + +\PrgNewFunction \IntCase { m m } { \int_case:nn {#1} {#2} } +\PrgNewFunction \IntCaseT { m m n } { \int_case:nnT {#1} {#2} {#3} } +\PrgNewFunction \IntCaseF { m m n } { \int_case:nnF {#1} {#2} {#3} } +\PrgNewFunction \IntCaseTF { m m n n } { \int_case:nnTF {#1} {#2} {#3} {#4} } + +%%% -------------------------------------------------------- +%%> \section{Interfaces for Floating Point Numbers (Fp)} +%%% -------------------------------------------------------- + +\fp_set_eq:NN \cZeroFp \c_zero_fp +\fp_set_eq:NN \cMinusZeroFp \c_minus_zero_fp +\fp_set_eq:NN \cOneFp \c_one_fp +\fp_set_eq:NN \cInfFp \c_inf_fp +\fp_set_eq:NN \cMinusInfFp \c_minus_inf_fp +\fp_set_eq:NN \cEFp \c_e_fp +\fp_set_eq:NN \cPiFp \c_pi_fp +\fp_set_eq:NN \cOneDegreeFp \c_one_degree_fp + +\fp_new:N \lTmpaFp \fp_new:N \lTmpbFp \fp_new:N \lTmpcFp +\fp_new:N \lTmpiFp \fp_new:N \lTmpjFp \fp_new:N \lTmpkFp +\fp_new:N \l@Funx@Fp \fp_new:N \l@Funy@Fp \fp_new:N \l@Funz@Fp + +\fp_new:N \gTmpaFp \fp_new:N \gTmpbFp \fp_new:N \gTmpcFp +\fp_new:N \gTmpiFp \fp_new:N \gTmpjFp \fp_new:N \gTmpkFp +\fp_new:N \g@Funx@Fp \fp_new:N \g@Funy@Fp \fp_new:N \g@Funz@Fp + +\PrgNewFunction \FpEval { m } + { + \Result { \Expand { \fp_eval:n { #1 } } } + } + +\PrgNewFunction \FpMathAdd { m m } + { + \fp_set:Nn \l@Funx@Fp { \fp_eval:n { (#1) + (#2) } } + \Result { \FpUse \l@Funx@Fp } + } + +\PrgNewFunction \FpMathSub { m m } + { + \fp_set:Nn \l@Funx@Fp { \fp_eval:n { (#1) - (#2) } } + \Result { \FpUse \l@Funx@Fp } + } + +\PrgNewFunction \FpMathMult { m m } + { + \fp_set:Nn \l@Funx@Fp { \fp_eval:n { (#1) * (#2) } } + \Result { \FpUse \l@Funx@Fp } + } + +\PrgNewFunction \FpMathDiv { m m } + { + \fp_set:Nn \l@Funx@Fp { \fp_eval:n { (#1) / (#2) } } + \Result { \FpUse \l@Funx@Fp } + } + +\PrgNewFunction \FpMathSign { m } + { + \Result { \Expand { \fp_sign:n { #1 } } } + } + +\PrgNewFunction \FpMathAbs { m } + { + \Result { \Expand { \fp_abs:n { #1 } } } + } + +\PrgNewFunction \FpMathMax { m m } + { + \Result { \Expand { \fp_max:nn { #1 } { #2 } } } + } + +\PrgNewFunction \FpMathMin { m m } + { + \Result { \Expand { \fp_min:nn { #1 } { #2 } } } + } + +\PrgNewFunction \FpNew { M } { \fp_new:N #1 } + +\PrgNewFunction \FpConst { M m } { \fp_const:Nn #1 {#2} } + +\PrgNewFunction \FpUse { M } { \Result { \Expand { \fp_use:N #1 } } } + +\PrgNewFunction \FpLog { m } { \fp_log:n { #1 } } + +\PrgNewFunction \FpVarLog { M } { \fp_log:N #1 } + +\PrgNewFunction \FpShow { m } { \fp_show:n { #1 } } + +\PrgNewFunction \FpVarShow { M } { \fp_show:N #1 } + +\PrgNewFunction \FpSet { M m } + { + \__fun_do_assignment:Nnn #1 { \fp_gset:Nn #1 {#2} } { \fp_set:Nn #1 {#2} } + } + +\PrgNewFunction \FpSetEq { M M } + { + \__fun_do_assignment:Nnn #1 { \fp_gset_eq:NN #1 #2 } { \fp_set_eq:NN #1 #2 } + } + +\PrgNewFunction \FpZero { M } + { + \__fun_do_assignment:Nnn #1 { \fp_gzero:N #1 } { \fp_zero:N #1 } + } + +\PrgNewFunction \FpZeroNew { M } + { + \__fun_do_assignment:Nnn #1 { \fp_gzero_new:N #1 } { \fp_zero_new:N #1 } + } + +\PrgNewFunction \FpAdd { M m } + { + \__fun_do_assignment:Nnn #1 { \fp_gadd:Nn #1 {#2} } { \fp_add:Nn #1 {#2} } + } + +\PrgNewFunction \FpSub { M m } + { + \__fun_do_assignment:Nnn #1 { \fp_gsub:Nn #1 {#2} } { \fp_sub:Nn #1 {#2} } + } + +\PrgNewFunction \FpStepInline { m m m n } + { + \fp_step_inline:nnnn { #1 } { #2 } { #3 } { #4 } + } + +\PrgNewFunction \FpStepVariable { m m m M n } + { + \fp_step_variable:nnnNn { #1 } { #2 } { #3 } #4 { #5 } + } + +\PrgNewConditional \FpIfExist { M } + { + \fp_if_exist:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \FpCompare { m N m } + { + \fp_compare:nNnTF {#1} #2 {#3} + { \Result { \cTrueBool } } + { \Result { \cFalseBool } } + } + +%%% -------------------------------------------------------- +%%> \section{Interfaces for Dimensions (Dim)} +%%% -------------------------------------------------------- + +\cs_set_eq:NN \cMaxDim \c_max_dim +\cs_set_eq:NN \cZeroDim \c_zero_dim + +\dim_new:N \lTmpaDim \dim_new:N \lTmpbDim \dim_new:N \lTmpcDim +\dim_new:N \lTmpiDim \dim_new:N \lTmpjDim \dim_new:N \lTmpkDim +\dim_new:N \l@Funx@Dim \dim_new:N \l@Funy@Dim \dim_new:N \l@Funz@Dim + +\dim_new:N \gTmpaDim \dim_new:N \gTmpbDim \dim_new:N \gTmpcDim +\dim_new:N \gTmpiDim \dim_new:N \gTmpjDim \dim_new:N \gTmpkDim +\dim_new:N \g@Funx@Dim \dim_new:N \g@Funy@Dim \dim_new:N \g@Funz@Dim + +\PrgNewFunction \DimEval { m } + { + \Result { \Expand { \dim_eval:n { #1 } } } + } + +\PrgNewFunction \DimMathAdd { m m } + { + \dim_set:Nn \l@Funx@Dim { \dim_eval:n { (#1) + (#2) } } + \Result { \Value \l@Funx@Dim } + } + +\PrgNewFunction \DimMathSub { m m } + { + \dim_set:Nn \l@Funx@Dim { \dim_eval:n { (#1) - (#2) } } + \Result { \Value \l@Funx@Dim } + } + +\PrgNewFunction \DimMathSign { m } + { + \Result { \Expand { \dim_sign:n { #1 } } } + } + +\PrgNewFunction \DimMathAbs { m } + { + \Result { \Expand { \dim_abs:n { #1 } } } + } + +\PrgNewFunction \DimMathMax { m m } + { + \Result { \Expand { \dim_max:nn { #1 } { #2 } } } + } + +\PrgNewFunction \DimMathMin { m m } + { + \Result { \Expand { \dim_min:nn { #1 } { #2 } } } + } + +\PrgNewFunction \DimMathRatio { m m } + { + \Result { \Expand { \dim_ratio:nn { #1 } { #2 } } } + } + +\PrgNewFunction \DimNew { M } { \dim_new:N #1 } + +\PrgNewFunction \DimConst { M m } { \dim_const:Nn #1 {#2} } + +\PrgNewFunction \DimUse { M } { \Result { \Value #1 } } + +\PrgNewFunction \DimLog { m } { \dim_log:n { #1 } } + +\PrgNewFunction \DimVarLog { M } { \dim_log:N #1 } + +\PrgNewFunction \DimShow { m } { \dim_show:n { #1 } } + +\PrgNewFunction \DimVarShow { M } { \dim_show:N #1 } + +\PrgNewFunction \DimSet { M m } + { + \__fun_do_assignment:Nnn #1 { \dim_gset:Nn #1 {#2} } { \dim_set:Nn #1 {#2} } + } + +\PrgNewFunction \DimSetEq { M M } + { + \__fun_do_assignment:Nnn #1 { \dim_gset_eq:NN #1 #2 } { \dim_set_eq:NN #1 #2 } + } + +\PrgNewFunction \DimZero { M } + { + \__fun_do_assignment:Nnn #1 { \dim_gzero:N #1 } { \dim_zero:N #1 } + } + +\PrgNewFunction \DimZeroNew { M } + { + \__fun_do_assignment:Nnn #1 { \dim_gzero_new:N #1 } { \dim_zero_new:N #1 } + } + +\PrgNewFunction \DimAdd { M m } + { + \__fun_do_assignment:Nnn #1 { \dim_gadd:Nn #1 {#2} } { \dim_add:Nn #1 {#2} } + } + +\PrgNewFunction \DimSub { M m } + { + \__fun_do_assignment:Nnn #1 { \dim_gsub:Nn #1 {#2} } { \dim_sub:Nn #1 {#2} } + } + +\PrgNewFunction \DimStepInline { m m m n } + { + \dim_step_inline:nnnn { #1 } { #2 } { #3 } { #4 } + } + +\PrgNewFunction \DimStepVariable { m m m M n } + { + \dim_step_variable:nnnNn { #1 } { #2 } { #3 } #4 { #5 } + } + +\PrgNewConditional \DimIfExist { M } + { + \dim_if_exist:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \DimCompare { m N m } + { + \dim_compare:nNnTF {#1} #2 {#3} + { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewFunction \DimCase { m m } { \dim_case:nn {#1} {#2} } +\PrgNewFunction \DimCaseT { m m n } { \dim_case:nnT {#1} {#2} {#3} } +\PrgNewFunction \DimCaseF { m m n } { \dim_case:nnF {#1} {#2} {#3} } +\PrgNewFunction \DimCaseTF { m m n n } { \dim_case:nnTF {#1} {#2} {#3} {#4} } + +%%% -------------------------------------------------------- +%%> \section{Interfaces for Sorting Functions (Sort)} +%%% -------------------------------------------------------- + +\cs_set_eq:NN \SortReturnSame \sort_return_same: +\cs_set_eq:NN \SortReturnSwapped \sort_return_swapped: + +%%% -------------------------------------------------------- +%%> \section{Interfaces for Comma Separated Lists (Clist)} +%%% -------------------------------------------------------- + +\clist_new:N \lTmpaClist \clist_new:N \lTmpbClist \clist_new:N \lTmpcClist +\clist_new:N \lTmpiClist \clist_new:N \lTmpjClist \clist_new:N \lTmpkClist +\clist_new:N \l@Funx@Clist \clist_new:N \l@Funy@Clist \clist_new:N \l@Funz@Clist + +\clist_new:N \gTmpaClist \clist_new:N \gTmpbClist \clist_new:N \gTmpcClist +\clist_new:N \gTmpiClist \clist_new:N \gTmpjClist \clist_new:N \gTmpkClist +\clist_new:N \g@Funx@Clist \clist_new:N \g@Funy@Clist \clist_new:N \g@Funz@Clist + +\clist_set_eq:NN \cEmptyClist \c_empty_clist + +\PrgNewFunction \ClistNew { M } { \clist_new:N #1 } + +\PrgNewFunction \ClistLog { m } { \clist_log:n { #1 } } + +\PrgNewFunction \ClistVarLog { M } { \clist_log:N #1 } + +\PrgNewFunction \ClistShow { m } { \clist_show:n { #1 } } + +\PrgNewFunction \ClistVarShow { M } { \clist_show:N #1 } + +\PrgNewFunction \ClistVarJoin { M m } + { + \Expand { \clist_use:Nn #1 { #2 } } + } + +\PrgNewFunction \ClistVarJoinExtended { M m m m } + { + \Expand { \clist_use:Nnnn #1 { #2 } { #3 } { #4 } } + } + +\PrgNewFunction \ClistJoin { m m } + { + \Expand { \clist_use:nn { #1 } { #2 } } + } + +\PrgNewFunction \ClistJoinExtended { m m m m } + { + \Expand { \clist_use:nnnn { #1 } { #2 } { #3 } { #4 } } + } + +\PrgNewFunction \ClistConst { M m } { \clist_const:Nn #1 { #2 } } + +\PrgNewFunction \ClistSet { M m } + { + \__fun_do_assignment:Nnn #1 + { \clist_gset:Nn #1 {#2} } { \clist_set:Nn #1 {#2} } + } + +\PrgNewFunction \ClistSetEq { M M } + { + \__fun_do_assignment:Nnn #1 + { \clist_gset_eq:NN #1 #2 } { \clist_set_eq:NN #1 #2 } + } + +\PrgNewFunction \ClistSetFromSeq { M M } + { + \__fun_do_assignment:Nnn #1 + { \clist_gset_from_seq:NN #1 #2 } { \clist_set_from_seq:NN #1 #2 } + } + +\PrgNewFunction \ClistConcat { M M M } + { + \__fun_do_assignment:Nnn #1 + { \clist_gconcat:NNN #1 #2 #3 } { \clist_concat:NNN #1 #2 #3 } + } + +\PrgNewFunction \ClistClear { M } + { + \__fun_do_assignment:Nnn #1 { \clist_gclear:N #1 } { \clist_clear:N #1 } + } + +\PrgNewFunction \ClistClearNew { M } + { + \__fun_do_assignment:Nnn #1 { \clist_gclear_new:N #1 } { \clist_clear_new:N #1 } + } + +\PrgNewFunction \ClistPutLeft { M m } + { + \__fun_do_assignment:Nnn #1 + { \clist_gput_left:Nn #1 {#2} } { \clist_put_left:Nn #1 {#2} } + } + +\PrgNewFunction \ClistPutRight { M m } + { + \__fun_do_assignment:Nnn #1 + { \clist_gput_right:Nn #1 {#2} } { \clist_put_right:Nn #1 {#2} } + } + +\PrgNewFunction \ClistRemoveDuplicates { M } + { + \__fun_do_assignment:Nnn #1 + { \clist_gremove_duplicates:N #1 } { \clist_remove_duplicates:N #1 } + } + +\PrgNewFunction \ClistRemoveAll { M m } + { + \__fun_do_assignment:Nnn #1 + { \clist_gremove_all:Nn #1 {#2} } { \clist_remove_all:Nn #1 {#2} } + } + +\PrgNewFunction \ClistReverse { M } + { + \__fun_do_assignment:Nnn #1 { \clist_greverse:N #1 } { \clist_reverse:N #1 } + } + +\PrgNewFunction \ClistSort { M m } + { + \__fun_do_assignment:Nnn #1 + { \clist_gsort:Nn #1 {#2} } { \clist_sort:Nn #1 {#2} } + } + +\PrgNewFunction \ClistCount { m } + { + \Result { \Expand { \clist_count:n { #1 } } } + } + +\PrgNewFunction \ClistVarCount { m } + { + \Result { \Expand { \clist_count:N #1 } } + } + +\PrgNewFunction \ClistGet { M M } { \clist_get:NN #1 #2 } +\PrgNewFunction \ClistGetT { M M n } { \clist_get:NNT #1 #2 {#3} } +\PrgNewFunction \ClistGetF { M M n } { \clist_get:NNF #1 #2 {#3} } +\PrgNewFunction \ClistGetTF { M M n n } { \clist_get:NNTF #1 #2 {#3} {#4} } + +\PrgNewFunction \ClistPop { M M } + { + \__fun_do_assignment:Nnn #1 + { \clist_gpop:NN #1 #2 } { \clist_pop:NN #1 #2 } + } +\PrgNewFunction \ClistPopT { M M n } + { + \__fun_do_assignment:Nnn #1 + { \clist_gpop:NNT #1 #2 {#3} } { \clist_pop:NNT #1 #2 {#3} } + } +\PrgNewFunction \ClistPopF { M M n } + { + \__fun_do_assignment:Nnn #1 + { \clist_gpop:NNF #1 #2 {#3} } { \clist_pop:NNF #1 #2 {#3} } + } +\PrgNewFunction \ClistPopTF { M M n n } + { + \__fun_do_assignment:Nnn #1 + { \clist_gpop:NNTF #1 #2 {#3} {#4} } { \clist_pop:NNTF #1 #2 {#3} {#4} } + } + +\PrgNewFunction \ClistPush { M m } + { + \__fun_do_assignment:Nnn #1 + { \clist_gpush:Nn #1 {#2} } { \clist_push:Nn #1 {#2} } + } + +\PrgNewFunction \ClistItem { m m } { \Expand { \clist_item:nn {#1} {#2} } } + +\PrgNewFunction \ClistVarItem { M m } { \Expand { \clist_item:Nn #1 {#2} } } + +\PrgNewFunction \ClistRandItem { m } { \Expand { \clist_rand_item:n {#1} } } + +\PrgNewFunction \ClistVarRandItem { M } { \Expand { \clist_rand_item:N #1 } } + +\PrgNewFunction \ClistMapInline { m n } + { + \clist_map_inline:nn {#1} {#2} + } + +\PrgNewFunction \ClistVarMapInline { M n } + { + \clist_map_inline:Nn #1 {#2} + } + +\PrgNewFunction \ClistMapVariable { m M n } + { + \clist_map_variable:nNn {#1} #2 {#3} + } + +\PrgNewFunction \ClistVarMapVariable { M M n } + { + \clist_map_variable:NNn #1 #2 {#3} + } + +\cs_set_eq:NN \ClistMapBreak \clist_map_break: + +\PrgNewConditional \ClistIfExist { M } + { + \clist_if_exist:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \ClistIfEmpty { m } + { + \clist_if_empty:nTF {#1} { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \ClistVarIfEmpty { m } + { + \clist_if_empty:NTF #1 { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \ClistIfIn { m m } + { + \clist_if_in:nnTF {#1} {#2} + { \Result { \cTrueBool } } { \Result { \cFalseBool } } + } + +\PrgNewConditional \ClistVarIfIn { M m } + { + \clist_if_in:NnTF #1 {#2} + { \Result { \cTrueBool } } { \Result { \cFalseBool } } } -- cgit v1.2.3