LATEX-L Archives

Mailing list for the LaTeX3 project


Options: Use Forum View

Use Monospaced Font
Show Text Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Lars Hellström <[log in to unmask]>
Reply To:
Mailing list for the LaTeX3 project <[log in to unmask]>
Mon, 24 Jan 2011 15:01:12 +0100
text/plain (51 lines)
Will Robertson skrev 2011-01-23 10.12:
> From a question on (, I
> finally got around to writing \clist_length:N and \clist_nth:Nn functions
> for extracting the length of a comma list, and extracting the n-th element
> of the same. Both are expandable. (Code attached below.)
> Questions: names? I think "length" is a good one although it doesn't match
> \tl_elt_count:N which is the equivalent for arbitrary token lists.

Isn't this "elt" an implementation detail for that type of list (various 
\@elt tokens in 2e come to mind), and thus something that should be kept 
internal rather than canonised in a public interface? The clean solution for 
*both* types of list is rather to use "length".

Moreover, I get a vague impression that the term `elt' is part of the 
pseudo-LISP heritage of LaTeX (emphasis on the "La"). If so, then that is 
IMHO another reason to avoid it, as that heritage is full of square pegs 
trying to fit in round holes.

> I didn't write "clist_nth" with a view of it being the permanent name, but
> now that I've written it I can't think of a (good) alternative. Any
> thoughts?

I think the verb you're looking for is "index", i.e., the command name would 
be clist_index.

> I assume that other packages dealing with comma-lists (such as etoolbox,
> etc.) contain similar functions. Is there functionality in l3clist that
> we're currently missing?

Since you're going the route of providing a numeric index interface to 
clists, some common operations within such an interface would be:

  first: Return index of first occurrence of a particular item within a clist,
         or -1 (given 0-based indices) if the item does not occur therein.
  last:  Return index of last occurrence of a particular item within a clist,
         or -1 (given 0-based indices) if the item does not occur therein.
         (Note: Slightly trickier to implement.)
  range: Return a subrange of the clist, i.e., if \a_clist is "a,b,c,d" then
         \clist_range:Nnn\a_clist{1}{2} returns "b,c". (I don't have an
         opinion as to what might be the best sense of "return" in this case.)
  replace: Replace the material in a subrange of the clist by some other
         clist material.

I can see first/last being useful for certain stack-style operations, e.g. 
cleartomark (like in Postscript, if you're familiar with that). But I would 
consider these fairly low priority features.

Lars Hellström