diff options
author | Karl Berry <karl@freefriends.org> | 2009-06-09 23:31:15 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2009-06-09 23:31:15 +0000 |
commit | 215b9a864d5829070bdc66ba736986eb72e5143e (patch) | |
tree | fe0882c81fc4ec945cee4b512f72eaa21ea5f791 /Master/texmf-dist/tex/latex/expl3/l3prg.sty | |
parent | df90ec06321940c2f066b05e12f1b5ab099105da (diff) |
expl3 1407 (9jun09)
git-svn-id: svn://tug.org/texlive/trunk@13686 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/expl3/l3prg.sty')
-rw-r--r-- | Master/texmf-dist/tex/latex/expl3/l3prg.sty | 472 |
1 files changed, 248 insertions, 224 deletions
diff --git a/Master/texmf-dist/tex/latex/expl3/l3prg.sty b/Master/texmf-dist/tex/latex/expl3/l3prg.sty index 7cc170fef4f..d696e412e06 100644 --- a/Master/texmf-dist/tex/latex/expl3/l3prg.sty +++ b/Master/texmf-dist/tex/latex/expl3/l3prg.sty @@ -15,7 +15,7 @@ %% Do not distribute a modified version of this file. %% %% -%% File: l3prg.dtx Copyright (C) 2005-2006 LaTeX3 project +%% File: l3prg.dtx Copyright (C) 2005-2009 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 @@ -33,7 +33,7 @@ %% %% The development version of the bundle can be found at %% -%% http://www.latex-project.org/cgi-bin/cvsweb.cgi/ +%% http://www.latex-project.org/svnroot/experimental/trunk/ %% %% for those people who are interested. %% @@ -48,301 +48,325 @@ %% %% ----------------------------------------------------------------------- \RequirePackage{l3names} -\GetIdInfo$Id: l3prg.dtx 768 2008-08-05 19:45:06Z morten $ +\GetIdInfo$Id: l3prg.dtx 1365 2009-05-31 17:26:17Z mittelba $ {L3 Experimental control structures} \ProvidesExplPackage {\filename}{\filedate}{\fileversion}{\filedescription} -\RequirePackage{l3quark} -\RequirePackage{l3toks} -\RequirePackage{l3int} -\def_new:Npn \mode_if_vertical_p: { - \if_mode_vertical: \c_true \else: \c_false\fi:} -\def_test_function_new:npn{mode_if_vertical:}{\if_mode_vertical:} -\def_new:Npn \mode_if_horizontal_p: { - \if_mode_horizontal: \c_true \else: \c_false\fi:} -\def_test_function_new:npn{mode_if_horizontal:}{\if_mode_horizontal:} -\def_new:Npn \mode_if_inner_p: { - \if_mode_inner: \c_true \else: \c_false\fi:} -\def_test_function_new:npn{mode_if_inner:}{\if_mode_inner:} -\def_test_function_new:npn{mode_if_math:} { - \scan_align_safe_stop: \if_mode_math: } -\def_new:Npn \group_align_safe_begin: { +\package_check_loaded_expl: +\prg_set_conditional:Npnn \mode_if_vertical: {p,TF,T,F}{ + \if_mode_vertical: + \prg_return_true: \else: \prg_return_false: \fi: +} +\prg_set_conditional:Npnn \mode_if_horizontal: {p,TF,T,F}{ + \if_mode_horizontal: + \prg_return_true: \else: \prg_return_false: \fi: +} +\prg_set_conditional:Npnn \mode_if_inner: {p,TF,T,F}{ + \if_mode_inner: + \prg_return_true: \else: \prg_return_false: \fi: +} +\prg_set_conditional:Npnn \mode_if_math: {p,TF,T,F}{ + \scan_align_safe_stop: \if_mode_math: + \prg_return_true: \else: \prg_return_false: \fi: +} +\cs_new_nopar:Npn \group_align_safe_begin: { \if_false:{\fi:\if_num:w`}=\c_zero\fi:} -\def_new:Npn \group_align_safe_end: {\if_num:w`{=\c_zero}\fi:} -\def_new:Npn \scan_align_safe_stop: { - \num_compare:nNnT \etex_currentgrouptype:D = \c_six +\cs_new_nopar:Npn \group_align_safe_end: {\if_num:w`{=\c_zero}\fi:} +\cs_new_nopar:Npn \scan_align_safe_stop: { + \intexpr_compare:nNnT \etex_currentgrouptype:D = \c_six { - \num_compare:nNnF \etex_lastnodetype:D = \c_zero + \intexpr_compare:nNnF \etex_lastnodetype:D = \c_zero { - \num_compare:nNnF \etex_lastnodetype:D = \c_seven + \intexpr_compare:nNnF \etex_lastnodetype:D = \c_seven \scan_stop: } } } -\def_new:Npn \prg_replicate:nn #1{ - \cs:w use_noop: - \exp_after:NN\prg_replicate_first_aux:N - \int_use:N \int_eval:n{#1} \cs_end: +\cs_new_nopar:Npn \prg_replicate:nn #1{ + \cs:w prg_do_nothing: + \exp_after:wN\prg_replicate_first_aux:N + \tex_romannumeral:D -`\q \intexpr_eval:n{#1} \cs_end: \cs_end: } -\def_new:Npn \prg_replicate_aux:N#1{ +\cs_new_nopar:Npn \prg_replicate_aux:N#1{ \cs:w prg_replicate_#1:n\prg_replicate_aux:N } -\def_new:Npn \prg_replicate_first_aux:N#1{ +\cs_new_nopar:Npn \prg_replicate_first_aux:N#1{ \cs:w prg_replicate_first_#1:n\prg_replicate_aux:N } -\def_new:Npn \prg_replicate_ :n #1{}% no, this is not a typo! -\def_long_new:cpn {prg_replicate_0:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}} -\def_long_new:cpn {prg_replicate_1:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1} -\def_long_new:cpn {prg_replicate_2:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1} -\def_long_new:cpn {prg_replicate_3:n}#1{ +\cs_new_nopar:Npn \prg_replicate_ :n #1{}% no, this is not a typo! +\cs_new:cpn {prg_replicate_0:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}} +\cs_new:cpn {prg_replicate_1:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1} +\cs_new:cpn {prg_replicate_2:n}#1{\cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1} +\cs_new:cpn {prg_replicate_3:n}#1{ \cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1} -\def_long_new:cpn {prg_replicate_4:n}#1{ +\cs_new:cpn {prg_replicate_4:n}#1{ \cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1} -\def_long_new:cpn {prg_replicate_5:n}#1{ +\cs_new:cpn {prg_replicate_5:n}#1{ \cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_6:n}#1{ +\cs_new:cpn {prg_replicate_6:n}#1{ \cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_7:n}#1{ +\cs_new:cpn {prg_replicate_7:n}#1{ \cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_8:n}#1{ +\cs_new:cpn {prg_replicate_8:n}#1{ \cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_9:n}#1{ +\cs_new:cpn {prg_replicate_9:n}#1{ \cs_end:{#1#1#1#1#1#1#1#1#1#1}#1#1#1#1#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_first_0:n}#1{\cs_end: } -\def_long_new:cpn {prg_replicate_first_1:n}#1{\cs_end: #1} -\def_long_new:cpn {prg_replicate_first_2:n}#1{\cs_end: #1#1} -\def_long_new:cpn {prg_replicate_first_3:n}#1{\cs_end: #1#1#1} -\def_long_new:cpn {prg_replicate_first_4:n}#1{\cs_end: #1#1#1#1} -\def_long_new:cpn {prg_replicate_first_5:n}#1{\cs_end: #1#1#1#1#1} -\def_long_new:cpn {prg_replicate_first_6:n}#1{\cs_end: #1#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_first_7:n}#1{\cs_end: #1#1#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_first_8:n}#1{\cs_end: #1#1#1#1#1#1#1#1} -\def_long_new:cpn {prg_replicate_first_9:n}#1{\cs_end: #1#1#1#1#1#1#1#1#1} -\def_long_new:NNn \prg_stepwise_function:nnnN 2{ - \num_compare:nNnTF{#2}<\c_zero - {\exp_args:No\prg_stepwise_function_decr:nnnN } - {\exp_args:No\prg_stepwise_function_incr:nnnN } - {\int_use:N\int_eval:n{#1}}{#2} -} -\def_long_new:NNn \prg_stepwise_function_incr:nnnN 4{ - \num_compare:nNnF {#1}>{#3} +\cs_new:cpn {prg_replicate_first_0:n}#1{\cs_end: } +\cs_new:cpn {prg_replicate_first_1:n}#1{\cs_end: #1} +\cs_new:cpn {prg_replicate_first_2:n}#1{\cs_end: #1#1} +\cs_new:cpn {prg_replicate_first_3:n}#1{\cs_end: #1#1#1} +\cs_new:cpn {prg_replicate_first_4:n}#1{\cs_end: #1#1#1#1} +\cs_new:cpn {prg_replicate_first_5:n}#1{\cs_end: #1#1#1#1#1} +\cs_new:cpn {prg_replicate_first_6:n}#1{\cs_end: #1#1#1#1#1#1} +\cs_new:cpn {prg_replicate_first_7:n}#1{\cs_end: #1#1#1#1#1#1#1} +\cs_new:cpn {prg_replicate_first_8:n}#1{\cs_end: #1#1#1#1#1#1#1#1} +\cs_new:cpn {prg_replicate_first_9:n}#1{\cs_end: #1#1#1#1#1#1#1#1#1} +\cs_new:Npn \prg_stepwise_function:nnnN #1#2{ + \intexpr_compare:nNnTF{#2}<\c_zero + {\exp_args:Nf\prg_stepwise_function_decr:nnnN } + {\exp_args:Nf\prg_stepwise_function_incr:nnnN } + {\intexpr_eval:n{#1}}{#2} +} +\cs_new:Npn \prg_stepwise_function_incr:nnnN #1#2#3#4{ + \intexpr_compare:nNnF {#1}>{#3} { #4{#1} - \exp_args:No \prg_stepwise_function_incr:nnnN - {\int_use:N\int_eval:n{#1 + #2}} + \exp_args:Nf \prg_stepwise_function_incr:nnnN + {\intexpr_eval:n{#1 + #2}} {#2}{#3}{#4} } } -\def_long_new:NNn \prg_stepwise_function_decr:nnnN 4{ - \num_compare:nNnF {#1}<{#3} +\cs_new:Npn \prg_stepwise_function_decr:nnnN #1#2#3#4{ + \intexpr_compare:nNnF {#1}<{#3} { #4{#1} - \exp_args:No \prg_stepwise_function_decr:nnnN - {\int_use:N\int_eval:n{#1 + #2}} + \exp_args:Nf \prg_stepwise_function_decr:nnnN + {\intexpr_eval:n{#1 + #2}} {#2}{#3}{#4} } } \int_new:N\g_prg_inline_level_int -\def_long_new:NNn\prg_stepwise_inline:nnnn 4{ +\cs_new:Npn\prg_stepwise_inline:nnnn #1#2#3#4{ \int_gincr:N \g_prg_inline_level_int - \gdef:cpn{prg_stepwise_inline_\int_use:N\g_prg_inline_level_int :n}##1{#4} - \num_compare:nNnTF {#2}<\c_zero - {\exp_args:Nco \prg_stepwise_inline_decr:Nnnn } - {\exp_args:Nco \prg_stepwise_inline_incr:Nnnn } + \cs_gset_nopar:cpn{prg_stepwise_inline_\int_use:N\g_prg_inline_level_int :n}##1{#4} + \intexpr_compare:nNnTF {#2}<\c_zero + {\exp_args:Ncf \prg_stepwise_inline_decr:Nnnn } + {\exp_args:Ncf \prg_stepwise_inline_incr:Nnnn } {prg_stepwise_inline_\int_use:N\g_prg_inline_level_int :n} - {\int_use:N\int_eval:n{#1}} {#2} {#3} + {\intexpr_eval:n{#1}} {#2} {#3} \int_gdecr:N \g_prg_inline_level_int } -\def_long_new:NNn \prg_stepwise_inline_incr:Nnnn 4{ - \num_compare:nNnF {#2}>{#4} +\cs_new:Npn \prg_stepwise_inline_incr:Nnnn #1#2#3#4{ + \intexpr_compare:nNnF {#2}>{#4} { #1{#2} - \exp_args:NNo \prg_stepwise_inline_incr:Nnnn #1 - {\int_use:N\int_eval:n{#2 + #3}} {#3}{#4} + \exp_args:NNf \prg_stepwise_inline_incr:Nnnn #1 + {\intexpr_eval:n{#2 + #3}} {#3}{#4} } } -\def_long_new:NNn \prg_stepwise_inline_decr:Nnnn 4{ - \num_compare:nNnF {#2}<{#4} +\cs_new:Npn \prg_stepwise_inline_decr:Nnnn #1#2#3#4{ + \intexpr_compare:nNnF {#2}<{#4} { #1{#2} - \exp_args:NNo \prg_stepwise_inline_decr:Nnnn #1 - {\int_use:N\int_eval:n{#2 + #3}} {#3}{#4} + \exp_args:NNf \prg_stepwise_inline_decr:Nnnn #1 + {\intexpr_eval:n{#2 + #3}} {#3}{#4} } } -\def_long_new:NNn \prg_stepwise_variable:nnnNn 2 { - \num_compare:nNnTF {#2}<\c_zero - {\exp_args:No\prg_stepwise_variable_decr:nnnNn} - {\exp_args:No\prg_stepwise_variable_incr:nnnNn} - {\int_use:N\int_eval:n{#1}}{#2} +\cs_new:Npn \prg_stepwise_variable:nnnNn #1#2 { + \intexpr_compare:nNnTF {#2}<\c_zero + {\exp_args:Nf\prg_stepwise_variable_decr:nnnNn} + {\exp_args:Nf\prg_stepwise_variable_incr:nnnNn} + {\intexpr_eval:n{#1}}{#2} } -\def_long_new:NNn \prg_stepwise_variable_incr:nnnNn 5 { - \num_compare:nNnF {#1}>{#3} +\cs_new:Npn \prg_stepwise_variable_incr:nnnNn #1#2#3#4#5 { + \intexpr_compare:nNnF {#1}>{#3} { - \def:Npn #4{#1} #5 - \exp_args:No \prg_stepwise_variable_incr:nnnNn - {\int_use:N\int_eval:n{#1 + #2}}{#2}{#3}#4{#5} + \cs_set_nopar:Npn #4{#1} #5 + \exp_args:Nf \prg_stepwise_variable_incr:nnnNn + {\intexpr_eval:n{#1 + #2}}{#2}{#3}#4{#5} } } -\def_long_new:NNn \prg_stepwise_variable_decr:nnnNn 5 { - \num_compare:nNnF {#1}<{#3} +\cs_new:Npn \prg_stepwise_variable_decr:nnnNn #1#2#3#4#5 { + \intexpr_compare:nNnF {#1}<{#3} { - \def:Npn #4{#1} #5 - \exp_args:No \prg_stepwise_variable_decr:nnnNn - {\int_use:N\int_eval:n{#1 + #2}}{#2}{#3}#4{#5} + \cs_set_nopar:Npn #4{#1} #5 + \exp_args:Nf \prg_stepwise_variable_decr:nnnNn + {\intexpr_eval:n{#1 + #2}}{#2}{#3}#4{#5} } } -\def_new:Npn \bool_new:N #1 { \let_new:NN #1 \c_false } -\def_new:Npn \bool_new:c #1 { \let_new:cN {#1} \c_false } -\def_new:Npn \bool_set_true:N #1 { \let:NN #1 \c_true } -\def_new:Npn \bool_set_true:c #1 { \let:cN {#1} \c_true } -\def_new:Npn \bool_set_false:N #1 { \let:NN #1 \c_false } -\def_new:Npn \bool_set_false:c #1 { \let:cN {#1} \c_false } -\def_new:Npn \bool_gset_true:N #1 { \glet:NN #1 \c_true } -\def_new:Npn \bool_gset_true:c #1 { \glet:cN {#1} \c_true } -\def_new:Npn \bool_gset_false:N #1 { \glet:NN #1 \c_false } -\def_new:Npn \bool_gset_false:c #1 { \glet:cN {#1} \c_false } -\let_new:NN \bool_set_eq:NN \let:NN -\let_new:NN \bool_set_eq:Nc \let:Nc -\let_new:NN \bool_set_eq:cN \let:cN -\let_new:NN \bool_set_eq:cc \let:cc -\let_new:NN \bool_gset_eq:NN \glet:NN -\let_new:NN \bool_gset_eq:Nc \glet:Nc -\let_new:NN \bool_gset_eq:cN \glet:cN -\let_new:NN \bool_gset_eq:cc \glet:cc +\cs_new_nopar:Npn \bool_new:N #1 { \cs_new_eq:NN #1 \c_false_bool } +\cs_new_nopar:Npn \bool_new:c #1 { \cs_new_eq:cN {#1} \c_false_bool } +\cs_new_nopar:Npn \bool_set_true:N #1 { \cs_set_eq:NN #1 \c_true_bool } +\cs_new_nopar:Npn \bool_set_true:c #1 { \cs_set_eq:cN {#1} \c_true_bool } +\cs_new_nopar:Npn \bool_set_false:N #1 { \cs_set_eq:NN #1 \c_false_bool } +\cs_new_nopar:Npn \bool_set_false:c #1 { \cs_set_eq:cN {#1} \c_false_bool } +\cs_new_nopar:Npn \bool_gset_true:N #1 { \cs_gset_eq:NN #1 \c_true_bool } +\cs_new_nopar:Npn \bool_gset_true:c #1 { \cs_gset_eq:cN {#1} \c_true_bool } +\cs_new_nopar:Npn \bool_gset_false:N #1 { \cs_gset_eq:NN #1 \c_false_bool } +\cs_new_nopar:Npn \bool_gset_false:c #1 { \cs_gset_eq:cN {#1} \c_false_bool } +\cs_new_eq:NN \bool_set_eq:NN \cs_set_eq:NN +\cs_new_eq:NN \bool_set_eq:Nc \cs_set_eq:Nc +\cs_new_eq:NN \bool_set_eq:cN \cs_set_eq:cN +\cs_new_eq:NN \bool_set_eq:cc \cs_set_eq:cc +\cs_new_eq:NN \bool_gset_eq:NN \cs_gset_eq:NN +\cs_new_eq:NN \bool_gset_eq:Nc \cs_gset_eq:Nc +\cs_new_eq:NN \bool_gset_eq:cN \cs_gset_eq:cN +\cs_new_eq:NN \bool_gset_eq:cc \cs_gset_eq:cc \bool_new:N \l_tmpa_bool \bool_new:N \g_tmpa_bool -\def_test_function_new:npn{bool_if:N}#1{\if:w #1} -\def_new:Npn \bool_if:cTF{\exp_args:Nc\bool_if:NTF} -\def_new:Npn \bool_if:cT{\exp_args:Nc\bool_if:NT} -\def_new:Npn \bool_if:cF{\exp_args:Nc\bool_if:NF} -\def_new:Npn \bool_if_p:N #1 { #1 } -\let_new:NN \bool_if_p:c \cs_use:c -\def_long_new:Npn \bool_whiledo:NT #1 #2 { - \bool_if:NT #1 {#2 \bool_whiledo:NT #1 {#2}} -} -\def_new:Npn \bool_whiledo:cT{\exp_args:Nc\bool_whiledo:NT} -\def_long_new:Npn \bool_whiledo:NF #1 #2 { - \bool_if:NF #1 {#2 \bool_whiledo:NF #1 {#2}} -} -\def_new:Npn \bool_whiledo:cF{\exp_args:Nc\bool_whiledo:NF} -\def_long_new:Npn \bool_dowhile:NT #1 #2 { - #2 \bool_if:NT #1 {\bool_dowhile:NT #1 {#2}} -} -\def_new:Npn \bool_dowhile:cT{\exp_args:Nc\bool_dowhile:NT} -\def_long_new:Npn \bool_dowhile:NF #1 #2 { - #2 \bool_if:NF #1 {\bool_dowhile:NF #1 {#2}} -} -\def_new:Npn \bool_dowhiledo:cF{\exp_args:Nc\bool_dowhile:cF} -\def_new:Npn \bool_double_if:NNnnnn#1#2{ - \if_case:w \num_eval:w #1\scan_stop: - \if_case:w \num_eval:w #2\scan_stop: - \exp_after:NN\exp_after:NN\exp_after:NN \use_arg_i:nnnn - \else: - \exp_after:NN\exp_after:NN\exp_after:NN \use_arg_ii:nnnn - \fi: - \else: - \if_case:w \num_eval:w #2\scan_stop: - \exp_after:NN\exp_after:NN\exp_after:NN \use_arg_iii:nnnn - \else: - \exp_after:NN\exp_after:NN\exp_after:NN \use_arg_iv:nnnn - \fi: - \fi: -} -\def_new:Npn \bool_double_if:cNnnnn{\exp_args:Nc\bool_double_if:NNnnnn} -\def_new:Npn \bool_double_if:Ncnnnn{\exp_args:NNc\bool_double_if:NNnnnn} -\def_new:Npn \bool_double_if:ccnnnn{\exp_args:Ncc\bool_double_if:NNnnnn} -\def_long_new:Npn \prg_whiledo:nT #1#2{ - #1 {#2 \prg_whiledo:nT {#1}{#2}} -} -\def_long_new:Npn \prg_whiledo:nF #1#2{ - #1 {#2 \prg_whiledo:nF {#1}{#2}} -} -\def_long_new:Npn \prg_dowhile:nT #1#2{ - #2 #1 {\prg_dowhile:nT {#1}{#2}} -} -\def_long_new:Npn \prg_dowhile:nF #1#2{ - #2 #1 {\prg_dowhile:nF {#1}{#2}} -} -\def_long_new:Npn \predicate_p:n #1{ +\prg_set_conditional:Npnn \bool_if:N #1 {p,TF,T,F}{ + \if_bool:N #1 \prg_return_true: \else: \prg_return_false: \fi: +} +\cs_generate_variant:Nn \bool_if_p:N {c} +\cs_generate_variant:Nn \bool_if:NTF {c} +\cs_generate_variant:Nn \bool_if:NT {c} +\cs_generate_variant:Nn \bool_if:NF {c} +\cs_new:Npn \bool_while_do:Nn #1 #2 { + \bool_if:NT #1 {#2 \bool_while_do:Nn #1 {#2}} +} +\cs_generate_variant:Nn \bool_while_do:Nn {c} +\cs_new:Npn \bool_until_do:Nn #1 #2 { + \bool_if:NF #1 {#2 \bool_until_do:Nn #1 {#2}} +} +\cs_generate_variant:Nn \bool_until_do:Nn {c} +\cs_new:Npn \bool_do_while:Nn #1 #2 { + #2 \bool_if:NT #1 {\bool_do_while:Nn #1 {#2}} +} +\cs_generate_variant:Nn \bool_do_while:Nn {c} +\cs_new:Npn \bool_do_until:Nn #1 #2 { + #2 \bool_if:NF #1 {\bool_do_until:Nn #1 {#2}} +} +\cs_generate_variant:Nn \bool_do_until:Nn {c} +\cs_set:Npn \bool_if_p:n #1{ \group_align_safe_begin: - \exp_after:NN \predicate_auxi:NN - \int_to_roman:w-`\q #1 02\scan_stop: + \bool_get_next:N ( #1 )S } -\def_long_test_function_new:npn {predicate:n}#1{ - \group_align_safe_begin: - \if:w \exp_after:NN \predicate_auxi:NN - \int_to_roman:w-`\q #1 02\scan_stop: +\cs_set:Npn \bool_get_next:N #1{ + \use:c { + bool_ + \if_meaning:w !#1 ! \else: \if_meaning:w (#1 ( \else: p \fi: \fi: + :w + } #1 } -\def_new:Npn \predicate_auxi:NN 0 #1{ - \exp_after:NN \predicate_auxii:NNN \exp_after:NN #1 +\cs_set:cpn {bool_!:w}#1{ + \exp_after:wN \intexpr_if_even_p:n \tex_number:D \bool_get_next:N +} +\cs_set:cpn {bool_(:w}#1{ + \exp_after:wN \bool_cleanup:N \tex_number:D \bool_get_next:N +} +\cs_set:cpn {bool_p:w}{\exp_after:wN \bool_cleanup:N \tex_number:D } +\cs_new_nopar:Npn \bool_cleanup:N #1{ + \exp_after:wN \bool_choose:NN \exp_after:wN #1 \int_to_roman:w-`\q } -\def_new:Npn \predicate_auxii:NNN #1#2#3{ - \cs_use:c{predicate_#2#3_#1:w} } -\def_new:cpn{predicate_&&_0:w}{ - \exp_after:NN \predicate_auxi:NN\int_to_roman:w-`\q -} -\def_long_new:cpn{predicate_&&_1:w} #1 02\scan_stop:{ - \group_align_safe_end: 01} -\def_long_new:cpn{predicate_||_0:w} #1 02\scan_stop:{ - \group_align_safe_end: 00} -\def_new:cpn{predicate_||_1:w}{ - \exp_after:NN \predicate_auxi:NN\int_to_roman:w-`\q -} -\def_new:cpn{predicate_02_0:w}\scan_stop:{ \group_align_safe_end: 00 } -\def_new:cpn{predicate_02_1:w}\scan_stop:{ \group_align_safe_end: 01 } -\def_long_new:Npn \predicate_not_p:n #1{ - \if:w \predicate_p:n{#1} \c_false \else: \c_true \fi: -} -\def_long:Npn \prg_case_int:nnn #1 #2 { - \exp_args:No \prg_case_int_aux:nnn {\num_value:w \int_eval:n{#1}} #2 +\cs_new_nopar:Npn \bool_choose:NN #1#2{ \use:c{bool_#2_#1:w} } +\cs_new_nopar:cpn{bool_&_1:w}&{\bool_get_next:N} +\cs_new_nopar:cpn{bool_|_0:w}|{\bool_get_next:N} +\cs_new_nopar:cpn{bool_)_0:w}{ \c_false_bool } +\cs_new_nopar:cpn{bool_)_1:w}{ \c_true_bool } +\cs_new_nopar:cpn{bool_S_0:w}{\group_align_safe_end: \c_false_bool } +\cs_new_nopar:cpn{bool_S_1:w}{\group_align_safe_end: \c_true_bool } +\cs_set:cpn{bool_&_0:w}&{\bool_eval_skip_to_end:Nw \c_false_bool} +\cs_set:cpn{bool_|_1:w}|{\bool_eval_skip_to_end:Nw \c_true_bool} +\cs_set:Npn \bool_eval_skip_to_end:Nw #1#2){ + \bool_eval_skip_to_end_aux:Nw #1 #2(\q_no_value\q_nil{#2} +} +\cs_set:Npn \bool_eval_skip_to_end_aux:Nw #1#2(#3#4\q_nil#5{ + \quark_if_no_value:NTF #3 + { #1 } + { \bool_eval_skip_to_end_auxii:Nw #1 #5 } +} +\cs_set:Npn \bool_eval_skip_to_end_auxii:Nw #1#2(#3){ + \bool_eval_skip_to_end:Nw #1#3 ) +} +\cs_new:Npn \bool_set:Nn #1#2 {\tex_chardef:D #1 = \bool_if_p:n {#2}} +\cs_new:Npn \bool_gset:Nn #1#2 { + \tex_global:D \tex_chardef:D #1 = \bool_if_p:n {#2} +} +\cs_generate_variant:Nn \bool_set:Nn {c} +\cs_generate_variant:Nn \bool_gset:Nn {c} +\cs_new:Npn \bool_not_p:n #1{ \bool_if_p:n{!(#1)} } +\cs_new:Npn \bool_xor_p:nn #1#2 { + \intexpr_compare:nNnTF {\bool_if_p:n { #1 }} = {\bool_if_p:n { #2 }} + {\c_false_bool}{\c_true_bool} +} +\prg_set_conditional:Npnn \bool_if:n #1 {TF,T,F}{ + \if_predicate:w \bool_if_p:n{#1} + \prg_return_true: \else: \prg_return_false: \fi: +} +\cs_new:Npn \bool_while_do:nn #1#2 { + \bool_if:nT {#1} { #2 \bool_while_do:nn {#1}{#2} } +} +\cs_new:Npn \bool_until_do:nn #1#2 { + \bool_if:nF {#1} { #2 \bool_until_do:nn {#1}{#2} } +} +\cs_new:Npn \bool_do_while:nn #1#2 { + #2 \bool_if:nT {#1} { \bool_do_while:nn {#1}{#2} } +} +\cs_new:Npn \bool_do_until:nn #1#2 { + #2 \bool_if:nF {#1} { \bool_do_until:nn {#1}{#2} } +} +\cs_new:Npn \prg_case_int:nnn #1 #2 { + \exp_args:Nf \prg_case_int_aux:nnn { \intexpr_eval:n{#1}} #2 \q_recursion_tail ? \q_recursion_stop } -\def_long_new:Npn \prg_case_int_aux:nnn #1#2#3{ - \quark_if_recursion_tail_stop_do:nn{#2}{\use_arg_i:n} - \num_compare:nNnTF{#1}={#2} - { \use_arg_i_delimit_by_q_recursion_stop:nw {\use_arg_i:nn{#3}} } +\cs_new:Npn \prg_case_int_aux:nnn #1#2#3{ + \quark_if_recursion_tail_stop_do:nn{#2}{\use:n} + \intexpr_compare:nNnTF{#1}={#2} + { \prg_end_case:nw {#3} } { \prg_case_int_aux:nnn {#1}} } -\def_long:Npn \prg_case_dim:nnn #1 #2 { +\cs_new:Npn \prg_case_dim:nnn #1 #2 { \exp_args:No \prg_case_dim_aux:nnn {\dim_use:N \dim_eval:n{#1}} #2 \q_recursion_tail ? \q_recursion_stop } -\def_long_new:Npn \prg_case_dim_aux:nnn #1#2#3{ - \quark_if_recursion_tail_stop_do:nn{#2}{\use_arg_i:n} +\cs_new:Npn \prg_case_dim_aux:nnn #1#2#3{ + \quark_if_recursion_tail_stop_do:nn{#2}{\use:n} \dim_compare:nNnTF{#1}={#2} - { \use_arg_i_delimit_by_q_recursion_stop:nw {\use_arg_i:nn{#3}} } + { \prg_end_case:nw {#3} } { \prg_case_dim_aux:nnn {#1}} } -\def_long:Npn \prg_case_str:nnn #1 #2 { +\cs_new:Npn \prg_case_str:nnn #1 #2 { \prg_case_str_aux:nnn {#1} #2 \q_recursion_tail ? \q_recursion_stop } -\def_long_new:Npn \prg_case_str_aux:nnn #1#2#3{ - \quark_if_recursion_tail_stop_do:nn{#2}{\use_arg_i:n} - \tlist_if_eq:xxTF{#1}{#2} - { \use_arg_i_delimit_by_q_recursion_stop:nw {\use_arg_i:nn{#3}} } +\cs_new:Npn \prg_case_str_aux:nnn #1#2#3{ + \quark_if_recursion_tail_stop_do:nn{#2}{\use:n} + \tl_if_eq:xxTF{#1}{#2} + { \prg_end_case:nw {#3} } { \prg_case_str_aux:nnn {#1}} } -\def_new:NNn \prg_define_quicksort:nnn 3 { - \def_long:cNx{#1_quicksort:n}1{ +\cs_new:Npn \prg_case_tl:Nnn #1 #2 { + \prg_case_tl_aux:NNn #1 #2 + \q_recursion_tail ? \q_recursion_stop +} +\cs_new:Npn \prg_case_tl_aux:NNn #1#2#3{ + \quark_if_recursion_tail_stop_do:Nn #2{\use:n} + \tl_if_eq:NNTF #1 #2 + { \prg_end_case:nw {#3} } + { \prg_case_tl_aux:NNn #1} +} +\cs_new:Npn \prg_end_case:nw #1#2\q_recursion_stop#3{#1} + +\cs_new_nopar:Npn \prg_define_quicksort:nnn #1#2#3 { + \cs_set:cpx{#1_quicksort:n}##1{ \exp_not:c{#1_quicksort_start_partition:w} ##1 \exp_not:n{#2\q_nil#3\q_stop} } - \def_long:cNx{#1_quicksort_braced:n}1{ + \cs_set:cpx{#1_quicksort_braced:n}##1{ \exp_not:c{#1_quicksort_start_partition_braced:n} ##1 \exp_not:N\q_nil\exp_not:N\q_stop } - \def_long:cpx {#1_quicksort_start_partition:w} #2 ##1 #3{ + \cs_set:cpx {#1_quicksort_start_partition:w} #2 ##1 #3{ \exp_not:N \quark_if_nil:nT {##1}\exp_not:N \use_none_delimit_by_q_stop:w \exp_not:c{#1_quicksort_do_partition_i:nnnw} {##1}{}{} } - \def_long:cNx {#1_quicksort_start_partition_braced:n} 1 { + \cs_set:cpx {#1_quicksort_start_partition_braced:n} ##1 { \exp_not:N \quark_if_nil:nT {##1}\exp_not:N \use_none_delimit_by_q_stop:w \exp_not:c{#1_quicksort_do_partition_i_braced:nnnn} {##1}{}{} } - \def_long:cpx {#1_quicksort_do_partition_i:nnnw} ##1##2##3 #2 ##4 #3 { + \cs_set:cpx {#1_quicksort_do_partition_i:nnnw} ##1##2##3 #2 ##4 #3 { \exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw} { \exp_not:c{#1_quicksort_compare:nnTF}{##1}{##4} @@ -351,7 +375,7 @@ } {##1}{##2}{##3}{##4} } - \def_long:cNx {#1_quicksort_do_partition_i_braced:nnnn} 4 { + \cs_set:cpx {#1_quicksort_do_partition_i_braced:nnnn} ##1##2##3##4 { \exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw} { \exp_not:c{#1_quicksort_compare:nnTF}{##1}{##4} @@ -360,7 +384,7 @@ } {##1}{##2}{##3}{##4} } - \def_long:cpx {#1_quicksort_do_partition_ii:nnnw} ##1##2##3 #2 ##4 #3 { + \cs_set:cpx {#1_quicksort_do_partition_ii:nnnw} ##1##2##3 #2 ##4 #3 { \exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw} { \exp_not:c{#1_quicksort_compare:nnTF}{##4}{##1} @@ -369,7 +393,7 @@ } {##1}{##2}{##3}{##4} } - \def_long:cNx {#1_quicksort_do_partition_ii_braced:nnnn} 4 { + \cs_set:cpx {#1_quicksort_do_partition_ii_braced:nnnn} ##1##2##3##4 { \exp_not:N \quark_if_nil:nTF {##4} \exp_not:c {#1_do_quicksort_braced:nnnnw} { \exp_not:c{#1_quicksort_compare:nnTF}{##4}{##1} @@ -378,31 +402,31 @@ } {##1}{##2}{##3}{##4} } - \def_long:cNx {#1_quicksort_partition_less_i:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_less_i:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_i:nnnw}{##1}{##2}{{##4}##3}} - \def_long:cNx {#1_quicksort_partition_less_ii:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_less_ii:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_ii:nnnw}{##1}{##2}{##3{##4}}} - \def_long:cNx {#1_quicksort_partition_greater_i:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_greater_i:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_i:nnnw}{##1}{{##4}##2}{##3}} - \def_long:cNx {#1_quicksort_partition_greater_ii:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_greater_ii:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_ii:nnnw}{##1}{##2{##4}}{##3}} - \def_long:cNx {#1_quicksort_partition_less_i_braced:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_less_i_braced:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_i_braced:nnnn}{##1}{##2}{{##4}##3}} - \def_long:cNx {#1_quicksort_partition_less_ii_braced:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_less_ii_braced:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_ii_braced:nnnn}{##1}{##2}{##3{##4}}} - \def_long:cNx {#1_quicksort_partition_greater_i_braced:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_greater_i_braced:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_i_braced:nnnn}{##1}{{##4}##2}{##3}} - \def_long:cNx {#1_quicksort_partition_greater_ii_braced:nnnn} 4{ + \cs_set:cpx {#1_quicksort_partition_greater_ii_braced:nnnn} ##1##2##3##4{ \exp_not:c{#1_quicksort_do_partition_ii_braced:nnnn}{##1}{##2{##4}}{##3}} - \def_long:cpx {#1_do_quicksort_braced:nnnnw} ##1##2##3##4\q_stop { + \cs_set:cpx {#1_do_quicksort_braced:nnnnw} ##1##2##3##4\q_stop { \exp_not:c{#1_quicksort_braced:n}{##2} \exp_not:c{#1_quicksort_function:n}{##1} \exp_not:c{#1_quicksort_braced:n}{##3} } } \prg_define_quicksort:nnn {prg}{}{} -\let:NN \prg_quicksort_function:n \ERROR -\let:NN \prg_quicksort_compare:nnTF \ERROR +\cs_set:Npn \prg_quicksort_function:n {\ERROR} +\cs_set:Npn \prg_quicksort_compare:nnTF {\ERROR} %% %% %% End of file `l3prg.sty'. |