Lista de tokens de LaTeX 3, variables, funciones de mapeo, diferencias entre mapeo en línea y funciones

Lista de tokens de LaTeX 3, variables, funciones de mapeo, diferencias entre mapeo en línea y funciones

Estoy buscando una buena explicación de las diferencias y casos de uso entre tl_map_function:nNy tl_map_inline:Nn. Proporciono un MWE inlineque también parece ser el más rápido.

\documentclass{article}
\usepackage{expl3,xparse}

\begin{document}
\ExplSyntaxOn
\cs_new:Nn\whatever:n{..{#1}~}
\tl_new:N  \tl_phd_temp_a
\tl_new:N  \tl_phd_temp_b
\tl_new:N  \tl_phd_temp_c
\DeclareDocumentCommand\Test{ }
    {
       \tl_set:Nn  \tl_phd_temp_a {Yiannis Mary John}
       \tl_set:Nn  \tl_phd_temp_b {{Lazarides}{Lou}{Smith}}
       \tl_concat:NNN \tl_phd_temp_c \tl_phd_temp_a \tl_phd_temp_b
       \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
   }   
\ExplSyntaxOff 
\Test
\end{document}

Respuesta1

Las funciones \tl_map_function:nNy \tl_map_function:NNson totalmente ampliables (con x-expansión, no f-expansión), mientras que la inlineversión no lo es.

La functionversión también es un poco más rápida.

Archivo de ejemplo

\documentclass{article}
\usepackage{expl3}

\begin{document}

\ExplSyntaxOn
\cs_new:Nn\whatever:n{}
\tl_new:N  \tl_phd_temp_a
\tl_new:N  \tl_phd_temp_b
\tl_new:N  \tl_phd_temp_c
\tl_set:Nn  \tl_phd_temp_a {Yiannis Mary John}
\tl_set:Nn  \tl_phd_temp_b {{Lazarides}{Lou}{Smith}}
\tl_concat:NNN \tl_phd_temp_c \tl_phd_temp_a \tl_phd_temp_b

\cs_new:Npn \xinline
 {
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
  \tl_map_inline:Nn\tl_phd_temp_c{\whatever:n{##1}}
 }
\cs_new:Npn \xfunction
 {
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
  \tl_map_function:NN\tl_phd_temp_c \whatever:n
 }

\cs_new:Npn \y #1
 {
  #1 #1 #1 #1 #1 #1 #1 #1 #1 #1
 }
\cs_new:Npn \z #1
 {
  \y{#1}\y{#1}\y{#1}\y{#1}\y{#1}
  \y{#1}\y{#1}\y{#1}\y{#1}\y{#1}
 }
\cs_new:Npn \zz #1
 {
  \z{#1}\z{#1}\z{#1}\z{#1}\z{#1}
  \z{#1}\z{#1}\z{#1}\z{#1}\z{#1}
 }
\cs_new:Npn \zzz #1
 {
  \zz{#1}\zz{#1}\zz{#1}\zz{#1}\zz{#1}
  \zz{#1}\zz{#1}\zz{#1}\zz{#1}\zz{#1}
 }

\ExplSyntaxOff

\zzz{\xinline}
%\zzz{\xfunction}

\stop

inlineversión

Esta es la respuesta detime

real    0m4.635s
user    0m4.613s
sys     0m0.016s

y este es el informe de la memoria

 140188 words of memory out of 5000000

functionversión

Esta es la respuesta detime

real    0m4.163s
user    0m4.139s
sys     0m0.020s

y este es el informe de la memoria

 140188 words of memory out of 5000000

¿Qué es preferible? Tiendo a considerarlo \tl_map_inline:nnmás fácil, porque no requiere definir una nueva función, pero cuando el código se vuelve complicado, functionse debe emplear la versión para mayor claridad. Debe adoptarse siempre que el mapeo a realizar utilice una función definida en otro lugar.

La inlineversión facilita la adición de puntos de interrupción; la functionversión necesita una función especialmente diseñada que contenga \tl_map_break:.

Además, la functionversión es un poco más compleja cuando el mapeo requiere más de un argumento (por ejemplo, estamos en un mapeo anidado, usando tanto el elemento externo como el interno).

información relacionada