I've been away for a while and I forget if this sort of question is appropriate, but here goes. Recently I wrote some code (in expl3 but I hope it's clear enough) and in hindsight I wonder on its style. Some comments after the snippet (slightly adapted from unicode-math):
\cs_new:Nn \um_if_char_spec:nNNT
{
% case 1:
\seq_if_in:NnT \l_um_mclass_range_seq {#3} { \use_none_delimit_by_q_nil:w }
% case 2:
\seq_if_in:NnT \l_um_cmd_range_seq {#2} { \use_none_delimit_by_q_nil:w }
% case 3:
\seq_map_inline:Nn \l_um_char_range_seq
{
\um_int_if_slot_in_range:nnT {#1} {##1}
{ \seq_map_break:n { \use_none_delimit_by_q_nil:w } }
}
% this executes if no match was found:
\use_none:nnn
\q_nil
\use:n
{
\clist_put_right:Nx \l_um_char_num_range_clist { \int_eval:n {#1} }
#4
}
}
The idea is that three possibilities can cause a match and execute some additional "true" code. Checking for these matches can be time-consuming so any true occurrence should immediately jump to the end. This is done by \use_none_delimit_by_q_nil:w which skips ahead to the \q_nil token and ignores everything in its way. At which point it executes the "true" code.
This could normally be done with a set of nested conditionals like so:
iftrue-(code)-else-(iftrue-(code)-else-(iftrue-(code))))
but I guess I didn't want to write out the (code) section several times — it seemed inelegant and error-prone. So what do you think? Is this code ugly? How would you write it?
unicode-mathpackage. – Bruno Le Floch Oct 26 '11 at 11:24