7

How to generate variants for functions with T/F arguments?

For example, I want make the first argument of \tl_if_eq:nn(TF) to be V. Should I write all the following:

\cs_generate_variant:Nn \tl_if_eq:nnT  { VnT }
\cs_generate_variant:Nn \tl_if_eq:nnF  { VnF }
\cs_generate_variant:Nn \tl_if_eq:nnTF { VnTF }

or just simply

\cs_generate_variant:Nn \tl_if_eq:nn { Vn }

By the way, if I only need to change the first argument, should I write the whole arg-spec list (i.e. Vn or V in the example)?

Update (2017-12-21)

Now there's a new function \prg_generate_conditional_variant:Nnn in l3candidate for this:

\prg_generate_conditional_variant:Nnn \tl_if_eq:nn { V } { T, F, TF }
9

As a general rule, the second argument to \cs_generate_variant:Nn can only list the argument types up to the last that must get changed.

Thus

\cs_generate_variant:Nn \tl_if_eq:nnT  { V }
\cs_generate_variant:Nn \tl_if_eq:nnT  { Vn }
\cs_generate_variant:Nn \tl_if_eq:nnT  { VnT }

are all equivalent. Similarly, if one wanted to vary the second argument to, say, x, the equivalent declarations would be

\cs_generate_variant:Nn \tl_if_eq:nnT  { nx }
\cs_generate_variant:Nn \tl_if_eq:nnT  { nxT }

In the case of (TF) trailing arguments, all different function should be generated:

\cs_generate_variant:Nn \tl_if_eq:nnT  { V }
\cs_generate_variant:Nn \tl_if_eq:nnF  { V }
\cs_generate_variant:Nn \tl_if_eq:nnTF { V }

Update

With the 2017-12-16 release of expl3 code, one can simplify the above to

\prg_generate_conditional_variant:Nnn \tl_if_eq:nn { V } { T, F, TF }

More generally, this is also possible for

\prg_new_conditional:Nnn \my_conditional_exp:nn { p, T, F, TF }

\prg_new_protected_conditional:Nnn \my__conditional_notexp:nn { T, F, TF }

(the :Npnn form can also be used, of course) so one can do

\prg_generate_conditional_variant:Nnn \my_conditional_exp:nn { V } { p, T, F, TF }

\prg_generate_conditional_variant:Nnn \my_conditional_notexp:nn { V } { T, F, TF }

The third argument to \prg_generate_conditional_variant:Nnn should only list suffixes that are present in the original definition of the conditional.

| improve this answer | |
  • I guess we should look to make use of this new functionality across the core code ... – Joseph Wright Dec 21 '17 at 9:37

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.