Parallel versus sequential binding
If someone tells you they want to replace A's with B's and B's with A's, they are implicitly talking about parallel assignment. They almost certainly don't mean Replace all A's with B's. Then replace all B's with A's."
They expect the name of the Swedish pop group ABBA to be turned into BAAB", but if you carry out the steps sequentially, you first get BBBB" and then AAAA".
Variations on this problem come up all the time. For example, it came up on a project I was working on with associative computing. Documentation specified a pair of assignment operations for an array of bits, and it was unclear whether the assignment was sequential or parallel. A colleague asked Is this let or let star?", alluding to a convention in Lisp programming. In Common Lisp, LET* executes a list of assignments sequentially, and LET executes a list of assignments in parallel.
This weekend I wrote a post about reversing Morse code sequences. If you transmit Morse code backwards, several pairs of letters are swapped. For example, G's (--.) become W's (.--) and vice versa.
To search for Morse code palindromes, words with symmetric Morse code representations, I searched a dictionary using parallel replacement. I did this by reversing the letters in a word and then replacing the letters by the letters with the reversed Morse code. You could do the latter step with the tr utility included with any Unix-like system.
tr ABDFGQNVULWY NVULWYABDFGQ
This says Replace A with N, B with V, ..., N with A, V with B, ... all in parallel." If tr did sequential replacement, the result would not be what we want, analogous to turning ABBA into AAAA above.
Not only does tr handle swaps, it handles more complex permutations. If you wanted to rotate A to B, B to C, and C to A in parallel, it handles this just fine.
$ echo ALCIBIADES | tr ABC BCA BLAICIBDES
It helps to have a name for this pattern. A formal description is sequential versus parallel binding, but I like the slang LET versus LET*. More people will understand the more verbose description, but if a group has to use the terms often, maybe they could adopt the LET vs LET* slang. And more importantly, maybe they could adopt the naming convention of using a star, or some other marker, to distinguish sequential and parallel APIs.
(Full disclosure: I initially got LET and LET* backward. So maybe the star thing isn't so mnemonic.)
Related postsThe post Parallel versus sequential binding first appeared on John D. Cook.