¿ªÔÆÌåÓý

Producing serial lists of varying length


 

What's the cleanest, most elegant way to set up a group or set of groups that outputs a serial list of varying length, so as to properly include the optional commas and final optional "and"?

E.g. "... with x, y, z, and aa." where the "aa" is always present, but the x, y, and z are all optional, so that the output will sometimes have two or more of the optional elements ("with x, y, and aa") sometimes just one of the optional elements ("with z and aa" - no comma) and sometimes with none of the optional elements ("with aa" - no "and").

Is the most elegant answer to first determine how many optional items are in the list, and then run a group with the three cases (zero optional item, one optional item, two or more optional items)? Is it to keep track of how many optional items are generated and to toggle the commas and the final "and" based on this? Is there another, better answer?

In particular, I'm trying to set up a "face description" table, where the eyes are always described at the end, but the various other facial features are only described if they're unusual in some way: Nose mentioned if it's big, small, or otherwise special, but not if it's average; mouth mentioned if it's generous, or thin and bloodless, or permenantly frowning, or otherwise odd, but not if it's normal; a scar mentioned if it's present, but not otherwise; and so on.

Join [email protected] to automatically receive all group messages.