
tl_map_function:nN
와 의 차이점과 사용 사례에 대한 좋은 설명을 찾고 있습니다 tl_map_inline:Nn
. 나는 inline
가장 빠른 것으로 보이는 MWE를 제공합니다 .
\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
매핑에 두 개 이상의 인수가 필요한 경우 버전이 좀 더 복잡해집니다(예를 들어 외부 항목과 내부 항목을 모두 사용하는 중첩 매핑에 있음).