Can `function`s called in `tl_map_` and `seq_map_function`s be defined with more than one argument?
up vote
0
down vote
favorite
In providing an answer to my recent post "Preserving spaces when scanning tl
variables into a sequence using seq_set_split
" Enrico Gregorio defined __rn_add:n
to be called by tl_map_function
. In experimenting with tl_map_
and seq_map_function
s it occurred to me that the possibility of defining such functions having more than just one argument would be useful; for example __rn_add:nN
might use #1
for the tl item
and have #2
specify to which _seq
variable to add the item. I assume the _function
versions of tl_map
and seq_map
were intended to define processes for general use, while the _inline
versions provide greatest flexibility but need to be written anew for each tl_map_
and seq_map_inline
, or am I completely off the mark here?
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq {~} { #1 }
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
{
__rn_add:n { ~ }
tl_map_function:nN { ##1 } __rn_add:n
}
% print the data
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}
}
cs_new_protected:Nn __rn_add:n
{
seq_put_right:Nn l_rn_auxOne_seq { #1 }
}
ExplSyntaxOff
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
end{document}
expl3
add a comment |
up vote
0
down vote
favorite
In providing an answer to my recent post "Preserving spaces when scanning tl
variables into a sequence using seq_set_split
" Enrico Gregorio defined __rn_add:n
to be called by tl_map_function
. In experimenting with tl_map_
and seq_map_function
s it occurred to me that the possibility of defining such functions having more than just one argument would be useful; for example __rn_add:nN
might use #1
for the tl item
and have #2
specify to which _seq
variable to add the item. I assume the _function
versions of tl_map
and seq_map
were intended to define processes for general use, while the _inline
versions provide greatest flexibility but need to be written anew for each tl_map_
and seq_map_inline
, or am I completely off the mark here?
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq {~} { #1 }
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
{
__rn_add:n { ~ }
tl_map_function:nN { ##1 } __rn_add:n
}
% print the data
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}
}
cs_new_protected:Nn __rn_add:n
{
seq_put_right:Nn l_rn_auxOne_seq { #1 }
}
ExplSyntaxOff
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
end{document}
expl3
1
It's definitely useful and I think something will appear in the future.
– egreg
yesterday
I conclude it cannot be done yet.
– Reinhard Neuwirth
yesterday
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
In providing an answer to my recent post "Preserving spaces when scanning tl
variables into a sequence using seq_set_split
" Enrico Gregorio defined __rn_add:n
to be called by tl_map_function
. In experimenting with tl_map_
and seq_map_function
s it occurred to me that the possibility of defining such functions having more than just one argument would be useful; for example __rn_add:nN
might use #1
for the tl item
and have #2
specify to which _seq
variable to add the item. I assume the _function
versions of tl_map
and seq_map
were intended to define processes for general use, while the _inline
versions provide greatest flexibility but need to be written anew for each tl_map_
and seq_map_inline
, or am I completely off the mark here?
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq {~} { #1 }
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
{
__rn_add:n { ~ }
tl_map_function:nN { ##1 } __rn_add:n
}
% print the data
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}
}
cs_new_protected:Nn __rn_add:n
{
seq_put_right:Nn l_rn_auxOne_seq { #1 }
}
ExplSyntaxOff
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
end{document}
expl3
In providing an answer to my recent post "Preserving spaces when scanning tl
variables into a sequence using seq_set_split
" Enrico Gregorio defined __rn_add:n
to be called by tl_map_function
. In experimenting with tl_map_
and seq_map_function
s it occurred to me that the possibility of defining such functions having more than just one argument would be useful; for example __rn_add:nN
might use #1
for the tl item
and have #2
specify to which _seq
variable to add the item. I assume the _function
versions of tl_map
and seq_map
were intended to define processes for general use, while the _inline
versions provide greatest flexibility but need to be written anew for each tl_map_
and seq_map_inline
, or am I completely off the mark here?
documentclass{article}
usepackage[margin=1cm]{geometry}
usepackage{xparse}
ExplSyntaxOn
tl_new:N l_rn_auxOne_tl
tl_new:N l_rn_auxTwo_tl
seq_new:N l_rn_auxOne_seq
seq_new:N l_rn_auxTwo_seq
NewDocumentCommandmyScanText{m}
{
tl_set:Nn l_rn_auxOne_tl {#1}
seq_clear:N l_rn_auxOne_seq
% split at spaces
seq_set_split:Nnn l_rn_auxTwo_seq {~} { #1 }
% the first item is special, pop it out and split it
seq_pop_left:NN l_rn_auxTwo_seq l_rn_auxTwo_tl
tl_map_function:NN l_rn_auxTwo_tl __rn_add:n
% now do the other items, reinserting the space before them
seq_map_inline:Nn l_rn_auxTwo_seq
{
__rn_add:n { ~ }
tl_map_function:nN { ##1 } __rn_add:n
}
% print the data
textbf{tl~variable:}~tl_use:N l_rn_auxOne_tl\
textbf{seq~variable:}~seq_use:Nn l_rn_auxOne_seq {,}
}
cs_new_protected:Nn __rn_add:n
{
seq_put_right:Nn l_rn_auxOne_seq { #1 }
}
ExplSyntaxOff
%-----------------------
begin{document}
setlength{parindent}{0pt} % just for the example
myScanText{The quick brown fox jumps over the lazy dog.}
end{document}
expl3
expl3
asked 2 days ago
Reinhard Neuwirth
1,47611322
1,47611322
1
It's definitely useful and I think something will appear in the future.
– egreg
yesterday
I conclude it cannot be done yet.
– Reinhard Neuwirth
yesterday
add a comment |
1
It's definitely useful and I think something will appear in the future.
– egreg
yesterday
I conclude it cannot be done yet.
– Reinhard Neuwirth
yesterday
1
1
It's definitely useful and I think something will appear in the future.
– egreg
yesterday
It's definitely useful and I think something will appear in the future.
– egreg
yesterday
I conclude it cannot be done yet.
– Reinhard Neuwirth
yesterday
I conclude it cannot be done yet.
– Reinhard Neuwirth
yesterday
add a comment |
1 Answer
1
active
oldest
votes
up vote
2
down vote
accepted
If you need the expandability in a certain point, you can do
cs_set:Npn __rn_add:n #1 { rn_macro_with_two_args:nN { #1 } l_rn_addto_seq }
% ^ this before where you can, and then v this in an expandable context
tl_map_function:NN l_rn_auxii_tl __rn_add:n
But if you don't need expandability you can always do the inline version:
seq_map_inline:Nn l_rn_auxii_seq
{
__rn_add:n { ~ }
tl_map_inline:nn { ##1 }
{
rn_macro_with_two_args:nN { ###1 } l_rn_addto_seq
}
}
I experimented with cascading inline versions, except that at the second level I needed four#
to refer to the argument.
– Reinhard Neuwirth
yesterday
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
2
down vote
accepted
If you need the expandability in a certain point, you can do
cs_set:Npn __rn_add:n #1 { rn_macro_with_two_args:nN { #1 } l_rn_addto_seq }
% ^ this before where you can, and then v this in an expandable context
tl_map_function:NN l_rn_auxii_tl __rn_add:n
But if you don't need expandability you can always do the inline version:
seq_map_inline:Nn l_rn_auxii_seq
{
__rn_add:n { ~ }
tl_map_inline:nn { ##1 }
{
rn_macro_with_two_args:nN { ###1 } l_rn_addto_seq
}
}
I experimented with cascading inline versions, except that at the second level I needed four#
to refer to the argument.
– Reinhard Neuwirth
yesterday
add a comment |
up vote
2
down vote
accepted
If you need the expandability in a certain point, you can do
cs_set:Npn __rn_add:n #1 { rn_macro_with_two_args:nN { #1 } l_rn_addto_seq }
% ^ this before where you can, and then v this in an expandable context
tl_map_function:NN l_rn_auxii_tl __rn_add:n
But if you don't need expandability you can always do the inline version:
seq_map_inline:Nn l_rn_auxii_seq
{
__rn_add:n { ~ }
tl_map_inline:nn { ##1 }
{
rn_macro_with_two_args:nN { ###1 } l_rn_addto_seq
}
}
I experimented with cascading inline versions, except that at the second level I needed four#
to refer to the argument.
– Reinhard Neuwirth
yesterday
add a comment |
up vote
2
down vote
accepted
up vote
2
down vote
accepted
If you need the expandability in a certain point, you can do
cs_set:Npn __rn_add:n #1 { rn_macro_with_two_args:nN { #1 } l_rn_addto_seq }
% ^ this before where you can, and then v this in an expandable context
tl_map_function:NN l_rn_auxii_tl __rn_add:n
But if you don't need expandability you can always do the inline version:
seq_map_inline:Nn l_rn_auxii_seq
{
__rn_add:n { ~ }
tl_map_inline:nn { ##1 }
{
rn_macro_with_two_args:nN { ###1 } l_rn_addto_seq
}
}
If you need the expandability in a certain point, you can do
cs_set:Npn __rn_add:n #1 { rn_macro_with_two_args:nN { #1 } l_rn_addto_seq }
% ^ this before where you can, and then v this in an expandable context
tl_map_function:NN l_rn_auxii_tl __rn_add:n
But if you don't need expandability you can always do the inline version:
seq_map_inline:Nn l_rn_auxii_seq
{
__rn_add:n { ~ }
tl_map_inline:nn { ##1 }
{
rn_macro_with_two_args:nN { ###1 } l_rn_addto_seq
}
}
answered yesterday
Manuel
21k845105
21k845105
I experimented with cascading inline versions, except that at the second level I needed four#
to refer to the argument.
– Reinhard Neuwirth
yesterday
add a comment |
I experimented with cascading inline versions, except that at the second level I needed four#
to refer to the argument.
– Reinhard Neuwirth
yesterday
I experimented with cascading inline versions, except that at the second level I needed four
#
to refer to the argument.– Reinhard Neuwirth
yesterday
I experimented with cascading inline versions, except that at the second level I needed four
#
to refer to the argument.– Reinhard Neuwirth
yesterday
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2ftex.stackexchange.com%2fquestions%2f460876%2fcan-functions-called-in-tl-map-and-seq-map-functions-be-defined-with-mo%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
It's definitely useful and I think something will appear in the future.
– egreg
yesterday
I conclude it cannot be done yet.
– Reinhard Neuwirth
yesterday