5

I have the following command which gives the output I want. But I need an expandable version. I know that I need to use \seq_map_function:NN but I don't manage to pass the external argument correctly.

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn

\seq_new:N \l_uf_outer_seq \seq_set_from_clist:Nn \l_uf_outer_seq {key1,key2,key3}

\prop_new:N \l_uf_a_prop
     \prop_put:Nnn \l_uf_a_prop {key1}{aa}
     \prop_put:Nnn \l_uf_a_prop {key2}{ab}
     \prop_put:Nnn \l_uf_a_prop {keyX}{XX}

\prop_new:N \l_uf_b_prop
     \prop_put:Nnn \l_uf_b_prop {key1}{ba}
     \prop_put:Nnn \l_uf_b_prop {key3}{bb}


\cs_new:Nn \uf_handle_prop:n  
{
 \seq_map_inline:Nn \l_uf_outer_seq
  {
   \prop_if_in:cnT {l_uf_#1_prop} { ##1 } { \prop_item:cn{l_uf_#1_prop}{##1} \par }
  } 
}


\uf_handle_prop:n {a}


\cs_new:Nn \uf_handle_prop_exp:n
{
 ???
}

\tl_set:Nx \l_tmpa_tl { \uf_handle_prop_exp:n {a} } 


\ExplSyntaxOff
\end{document} 

2 Answers 2

3

One way could be to define multiple handling functions, one for each prop:

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn

\seq_new:N \l_uf_outer_seq
\seq_set_from_clist:Nn \l_uf_outer_seq {key1,key2,key3}

\prop_new:N \l_uf_a_prop
     \prop_put:Nnn \l_uf_a_prop {key1}{aa}
     \prop_put:Nnn \l_uf_a_prop {key2}{ab}
     \prop_put:Nnn \l_uf_a_prop {keyX}{XX}

\prop_new:N \l_uf_b_prop
     \prop_put:Nnn \l_uf_b_prop {key1}{ba}
     \prop_put:Nnn \l_uf_b_prop {key3}{bb}


\cs_new:Nn \uf_handle_prop:n  
{
 \seq_map_inline:Nn \l_uf_outer_seq
  {
    \prop_if_in:cnT {l_uf_#1_prop} { ##1 } { \prop_item:cn{l_uf_#1_prop}{##1} \par }
  } 
}


\uf_handle_prop:n {a}

\cs_new:Nn \uf_new_prop_handler:n
  {
    \cs_new:cn { uf_handling_prop_#1:n }
      {
        \prop_if_in:cnT { l_uf_#1_prop } { ##1 }
          { \prop_item:cn { l_uf_#1_prop } { ##1 } \par }
      }
  }
\uf_new_prop_handler:n { a }
\uf_new_prop_handler:n { b }

\cs_new:Nn \uf_handle_prop_exp:n
{
  \exp_args:NNc \seq_map_function:NN \l_uf_outer_seq { uf_handling_prop_#1:n }
}

\tl_set:Nx \l_tmpa_tl { \uf_handle_prop_exp:n {a} } 

\tl_show_analysis:N \l_tmpa_tl


\ExplSyntaxOff
\end{document} 
4
  • if nothing else works I will probably have to do it, but it is naturally quite an overhead -- I have quite a number of properties. Commented Mar 31, 2018 at 18:50
  • I thought about it while cooking and actually it is not so much overhead. Not worser than adding one or two fields to the property. Commented Mar 31, 2018 at 19:20
  • @UlrikeFischer Joseph's answer looks better though :)
    – Skillmon
    Commented Mar 31, 2018 at 19:29
  • But your answer is easier to extend to other cases and probably also easier to debug. Commented Mar 31, 2018 at 19:59
7

Doable if you use a delimited argument to 'pass' the name of the prop to an underlying \prop_item:cn:

\documentclass{article}
\usepackage{expl3}
\begin{document}
\ExplSyntaxOn

\seq_new:N \l_uf_outer_seq
\seq_set_from_clist:Nn \l_uf_outer_seq { key1 , key2 , key3 }

\prop_new:N \l_uf_a_prop

\prop_put:Nnn \l_uf_a_prop { key1 } { aa }
\prop_put:Nnn \l_uf_a_prop { key2 } { ab }
\prop_put:Nnn \l_uf_a_prop { keyX } { XX }

\prop_new:N \l_uf_b_prop
\prop_put:Nnn \l_uf_b_prop { key1 } { ba }
\prop_put:Nnn \l_uf_b_prop { key3 } { bb }

\cs_new_protected:Nn \uf_handle_prop:n  
  {
    \seq_map_inline:Nn \l_uf_outer_seq
      {
       \prop_if_in:cnT { l_uf_ #1 _prop } {##1}
         {
           \prop_item:cn {l_uf_ #1 _prop } { ##1 }
           \par
         }
      } 
  }


\uf_handle_prop:n {a}

\cs_new:Npn \uf_handle_prop_exp:n #1
  {
    \seq_map_function:NN
      \l_uf_outer_seq
      \__uf_handle_prop_exp:nw
    \__uf_handle_prop_exp_end:n {#1}
  }
\cs_new:Npn \__uf_handle_prop_exp:nw #1#2 \__uf_handle_prop_exp_end:n #3
  {
    \prop_if_in:cnT { l_uf_ #3 _prop } {#1}
      {
        \prop_item:cn {l_uf_ #3 _prop } {#1}
        \par
      }
    #2 \__uf_handle_prop_exp_end:n {#3}
  }
\cs_new_eq:NN \__uf_handle_prop_exp_end:n \use_none:n

\tl_set:Nx \l_tmpa_tl { \uf_handle_prop_exp:n {a} } 
\tl_show:N \l_tmpa_tl

\ExplSyntaxOff
\end{document} 

One might avoid two mappings at the cost of a little complexity by doing the look-up and passing the result forward:

\cs_new:Npn \__uf_handle_prop_exp:nw #1#2 \__uf_handle_prop_exp_end:n #3
  {
    \__uf_handle_prop_exp_aux:fnn
      { \prop_item:cn { l_uf_ #3 _prop } {#1} }
      {#2} {#3}
  }
\cs_new:Npn \__uf_handle_prop_exp_aux:nnn #1#2#3
  {
    \tl_if_blank:nF {#1}
      { #1 \par }
    #2 \__uf_handle_prop_exp_end:n {#3}
  }
\cs_generate_variant:Nn \__uf_handle_prop_exp_aux:nnn { f }
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .