
tl_map_function:nN
との違いと使用例についての適切な説明を探していますtl_map_inline:Nn
。 の MWE を提供しますが、inline
これが最も高速であると思われます。
\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}
答え1
関数\tl_map_function:nN
と は\tl_map_function:NN
完全に拡張可能ですが ( x
-expansion ではなくf
-expansion を使用)、inline
バージョンは拡張できません。
バージョンfunction
も少し速くなります。
サンプルファイル
\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
バージョン
これは、time
real 0m4.635s
user 0m4.613s
sys 0m0.016s
これはメモリレポートです
140188 words of memory out of 5000000
function
バージョン
これは、time
real 0m4.163s
user 0m4.139s
sys 0m0.020s
これはメモリレポートです
140188 words of memory out of 5000000
どちらが望ましいでしょうか?\tl_map_inline:nn
新しい関数を定義する必要がないので、私はより簡単だと考える傾向がありますが、コードが複雑になった場合は、function
より明確にするためにバージョンを使用する必要があります。実行するマッピングが他の場所で定義された関数を使用する場合は、常にこのバージョンを使用する必要があります。
バージョンinline
ではブレークポイントの追加が容易になります。function
バージョンでは、 を含む特別に調整された関数が必要です\tl_map_break:
。
また、function
マッピングに複数の引数が必要な場合、バージョンは少し複雑になります (たとえば、ネストされたマッピングで、外側の項目と内側の項目の両方を使用している場合)。