
Estoy buscando una buena explicación de las diferencias y casos de uso entre tl_map_function:nN
y tl_map_inline:Nn
. Proporciono un MWE inline
que 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:nN
y \tl_map_function:NN
son totalmente ampliables (con x
-expansión, no f
-expansión), mientras que la inline
versión no lo es.
La function
versió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
inline
versió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
function
versió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:nn
más fácil, porque no requiere definir una nueva función, pero cuando el código se vuelve complicado, function
se 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 inline
versión facilita la adición de puntos de interrupción; la function
versión necesita una función especialmente diseñada que contenga \tl_map_break:
.
Además, la function
versió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).