Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add \tl_item:nnTF and related functions #916

Open
blefloch opened this issue May 14, 2021 · 4 comments
Open

Add \tl_item:nnTF and related functions #916

blefloch opened this issue May 14, 2021 · 4 comments
Labels
consistency-of-language Making expl3 functions etc more predictable enhancement New feature or request

Comments

@blefloch
Copy link
Member

blefloch commented May 14, 2021

(This stems from discussions on an unrelated pull request #819). The \tl_item:nn function expands to nothing when the item is out of bounds. It would be good to provide TF versions of these functions which take the false branch when there is no item.

However it is not clear where the true branch should end up compared to the item itself. For consistency with all other TF functions \tl_item:nnTF { abc } { 2 } t f should give bt. This is essentially the same problem we had regarding \file_if_exist_input:nTF in #253, and the solution may be similar: add another argument to place before the found item. More precisely, I would suggest the following list of functions:

  • \tl_item:nnF, but not :nnT nor :nnTF;
  • \tl_item_apply:nnNTF (token list) (position) (n-type function) (true code) (false code), which gives either (false code) if the position is out of bounds, and (function){(item)} (true code) otherwise. Provide also the nnNT, nnNF, and nnN variants.

The indexing issue #892 will also apply here. All these comments about tl apply to clist, seq, prop at least.

@blefloch blefloch added expl3 enhancement New feature or request labels May 14, 2021
@blefloch
Copy link
Member Author

blefloch commented May 15, 2021

I'm worried that this would add 5 commands (:nnF, :nnN, :nnNT, :nnNF, :nnNTF) for each of N/c/n-type tl/clist/str and N/c type seq/prop, leading us to add 5×(3×3+2×2)=65 control sequences, plus some auxiliaries to implement them. Is that reasonable?

@car222222
Copy link
Contributor

In the l3 context, this 65 is a mere drop in the ocean!

But the general question of csname profligacy in l3, and probably elsewhere, does perhaps need some thought?

@wspr
Copy link
Contributor

wspr commented May 17, 2021 via email

@car222222
Copy link
Contributor

The need for prioritising the F case is related to the discussion in #926.

@blefloch blefloch added the consistency-of-language Making expl3 functions etc more predictable label May 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
consistency-of-language Making expl3 functions etc more predictable enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants