texlive[63640] Master/texmf-dist: functional (18jun22)

commits+karl at tug.org commits+karl at tug.org
Sat Jun 18 22:04:19 CEST 2022


Revision: 63640
          http://tug.org/svn/texlive?view=revision&revision=63640
Author:   karl
Date:     2022-06-18 22:04:18 +0200 (Sat, 18 Jun 2022)
Log Message:
-----------
functional (18jun22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/functional/functional.pdf
    trunk/Master/texmf-dist/doc/latex/functional/functional.tex
    trunk/Master/texmf-dist/tex/latex/functional/functional.sty

Modified: trunk/Master/texmf-dist/doc/latex/functional/functional.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/functional/functional.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/functional/functional.tex	2022-06-18 20:03:57 UTC (rev 63639)
+++ trunk/Master/texmf-dist/doc/latex/functional/functional.tex	2022-06-18 20:04:18 UTC (rev 63640)
@@ -3,7 +3,7 @@
 \documentclass[oneside]{book}
 \usepackage[a4paper,margin=2.5cm]{geometry}
 
-\newcommand*{\myversion}{2022G}
+\newcommand*{\myversion}{2022H}
 \newcommand*{\mydate}{Version \myversion\ (\the\year-\mylpad\month-\mylpad\day)}
 \newcommand*{\mylpad}[1]{\ifnum#1<10 0\the#1\else\the#1\fi}
 
@@ -640,6 +640,35 @@
 
 \chapter{Argument Using (\texttt{Use})}
 
+\section{Evaluating Functions}
+
+\begin{function}{\evalWhole}
+\begin{syntax}
+\cs{evalWhole} \Arg{tokens}
+\end{syntax}
+Evaluates all functions (defined with \cs{prgNewFunction}) in \meta{tokens}
+and replaces them with their return values, then returns the resulting tokens.
+\begin{codehigh}
+\tlSet \lTmpaTl {a\intEval{2*3}b}
+\tlSet \lTmpbTl {\evalWhole {a\intEval{2*3}b}}
+\end{codehigh}
+In the above example, |\lTmpaTl| contains |a\intEval{2*3}b|,
+while |\lTmpbTl| contains |a6b|.
+\end{function}
+
+\begin{function}{\evalNone}
+\begin{syntax}
+\cs{evalNone} \Arg{tokens}
+\end{syntax}
+Prevents the evaluation of its argument, returning \meta{tokens} without touching them.
+\begin{codehigh}
+\tlSet \lTmpaTl {\intEval{2*3}}
+\tlSet \lTmpbTl {\evalNone {\intEval{2*3}}}
+\end{codehigh}
+In the above example, |\lTmpaTl| contains |6|,
+while |\lTmpbTl| contains |\intEval{2*3}|.
+\end{function}
+
 \section{Expanding Tokens}
 
 \begin{function}{\expName}
@@ -2503,8 +2532,6 @@
 \begin{demohigh}
 \strCount {12\abc34}
 \end{demohigh}
-Due to naming conflict, you need to use \cs{strSize} instead of \cs{strCount}
-if you want to use \verb!functional! package together with \verb!xstring! package.
 \end{function}
 
 \begin{function}{\StVarCount}
@@ -2884,9 +2911,6 @@
 %character codes and not more elaborate considerations of grapheme
 %clusters, locale, etc.
 %\end{texnote}
-\par
-Due to naming conflict, you need to use \cs{strIfCompare}/\cs{strIfCompareTF} as a replacement
-if you want to use \verb!functional! package together with \verb!xstring! package.
 \end{function}
 
 \section{String Case Functions}

Modified: trunk/Master/texmf-dist/tex/latex/functional/functional.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/functional/functional.sty	2022-06-18 20:03:57 UTC (rev 63639)
+++ trunk/Master/texmf-dist/tex/latex/functional/functional.sty	2022-06-18 20:04:18 UTC (rev 63640)
@@ -14,7 +14,7 @@
 \NeedsTeXFormat{LaTeX2e}[2018-04-01]
 
 \RequirePackage{expl3}
-\ProvidesExplPackage{functional}{2022-05-22}{2022G}
+\ProvidesExplPackage{functional}{2022-06-18}{2022H}
   {^^JIntuitive Functional Programming Interface for LaTeX2}
 
 \cs_generate_variant:Nn \iow_log:n { V }
@@ -667,9 +667,13 @@
   }
 
 %%% --------------------------------------------------------
-%%> \subsection{Evaluating Functions inside Arguments}
+%%> \subsection{Evaluating Functions inside Arguments, I}
 %%% --------------------------------------------------------
 
+%% The function \__fun_eval_all:n is only used for arguments to be passed
+%% to \int_eval:n, \fp_eval:n, \dim_eval:n, and similar functions.
+%% It will not keep spaces, and will not distinguish between { and \bgroup.
+
 \tl_new:N \l__fun_eval_result_tl
 
 %% Evaluate all functions in #1 and replace them with their return values
@@ -710,6 +714,78 @@
   }
 
 %%% --------------------------------------------------------
+%%> \subsection{Evaluating Functions inside Arguments, II}
+%%% --------------------------------------------------------
+
+%% The function \evalWhole can be used in almost all use cases.
+%% It will keep spaces, and will distinguish between { and \bgroup.
+
+\prgNewFunction \evalWhole {n}
+  {
+    \__fun_eval_whole:n {#1}
+  }
+
+\tl_new:N \l__fun_eval_whole_tl
+\bool_new:N \l__fun_eval_none_bool
+
+%% Evaluate all functions in #1 and replace them with their return values
+\cs_new_protected:Npn \__fun_eval_whole:n #1
+  {
+    \fun_run_return_processor:nn
+      {
+        \bool_if:NTF \l__fun_eval_none_bool
+          {
+            \tl_put_right:Nx \l__fun_eval_whole_tl
+              { \exp_not:N \exp_not:n { \exp_not:V \gResultTl } }
+            \bool_set_false:N \l__fun_eval_none_bool
+            \__fun_eval_whole_aux:
+          }
+          { \exp_last_unbraced:NV \__fun_eval_whole_aux: \gResultTl }
+      }
+      {
+        \tl_clear:N \l__fun_eval_whole_tl
+        \__fun_eval_whole_aux: #1 \q_stop
+        %\tl_log:N \l__fun_eval_whole_tl
+        \tl_gset:Nx \gResultTl { \l__fun_eval_whole_tl }
+      }
+  }
+
+\cs_new_protected:Npn \__fun_eval_whole_aux:
+  {
+    %% ##1: <tokens> which both o-expand and x-expand to the current <token>;
+    %% ##2: <charcode>, a decimal number, −1 for a control sequence;
+    %% ##3: <catcode>, a capital hexadecimal digit, 0 for a control sequence.
+    \peek_analysis_map_inline:n
+      {
+        \int_compare:nNnTF {##2} = {-1} % control sequence
+          {
+            \exp_last_unbraced:No \token_if_eq_meaning:NNTF {##1} \q_stop
+              { \peek_analysis_map_break: }
+              {
+                \cs_if_exist:cTF
+                  { __fun_defined_ \exp_last_unbraced:No \cs_to_str:N {##1} : w }
+                  {
+                    \exp_last_unbraced:No \cs_if_eq:NNT {##1} \evalNone
+                      { \bool_set_true:N \l__fun_eval_none_bool }
+                    \peek_analysis_map_break:n
+                      {
+                        %% since ##1 is of the form "\exp_not:N \someFunc",
+                        %% we need to remove \exp_not:N first before evaluating
+                        \use:x {##1}
+                      }
+                  }
+                  { \tl_put_right:Nn \l__fun_eval_whole_tl {##1} }
+              }
+          }
+          { \tl_put_right:Nn \l__fun_eval_whole_tl {##1} }
+      }
+  }
+
+%% The function \evalNone prevent the evaluation of its argument
+
+\prgNewFunction \evalNone {n} { \tl_gset:Nn \gResultTl {#1} }
+
+%%% --------------------------------------------------------
 %%> \subsection{Printing Contents to the Input Stream}
 %%% --------------------------------------------------------
 



More information about the tex-live-commits mailing list.