Print

Print


Hi Bruno,

Great work!

On 14/03/2011, at 6:44 AM, Bruno Le Floch wrote:

> The only reason to not brace items is to be able to find an item
> faster using delimited arguments, and that this will only work for
> "nice" items (i.e., no brace, no `#`).

I was aware that the \seq_if_in functions had this restriction, but I didn't realise the internal structure of the seq was chosen for this reason; IMO braces turn up far too easily in input text to restrict them from such a data structure. (Imagine pushing a list of names to a stack, say, and someone is called "Hef{}feron"!)

> So I have the following more
> radical proposal: brace the arguments, and propose two searches,

We like radical proposals :)

> - one true search, which goes through each element and compares with
> `\tl_if_eq:nn`,
> 
> - a `str`-like one, which detokenizes the seq, and searches for the
> detokenized version of `\seq_elt:n {<item>}` with a delimited argument
> (now ok, since everything is detokenized).
> 
> That proposal would make the code much, much clearer in my opinion.
> Also slightly faster, but not more than two-fold.

I did a quick comparison, and it seems like the delimited-argument search is around about 10-20 times faster than mapping, even for relatively large seqs (several thousand (small) elements, which takes a surprisingly long time to create using \seq_push:Nn).

So I'm generally in favour of this suggestion. But I wonder if there is some downside to using braces that I'm not experienced enough to see. (I can't think off the top of my head of another stack-like data structures in TeX that uses braces.) Can anyone comment further on this?

-- Will