|
Insufficiently general syntax Bah. Twice in the past week I've been bitten by pieces of badly thought out syntax which look general but aren't. (Curiously, both have involved braces.) In bash 3, the brace expansion syntax has been extended to permit numeric ranges separated by ‘..’, so that where you could previously have written ‘a{0,1,2}’ and had it expand to ‘a0 a1 a2’, you can now achieve the same thing by writing ‘a{0..2}’. However: $ echo a{0..9} a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 $ echo a{A,B,C,D,E,F} aA aB aC aD aE aF $ echo a{0..9,A,B,C,D,E,F} a0..9 aA aB aC aD aE aF
Bah! You can only get the two types of braced thing to combine by using a second pair of braces inside the first, which don't look as if they ought to be necessary, but they are: $ echo a{{0..9},A,B,C,D,E,F} a0 a1 a2 a3 a4 a5 a6 a7 a8 a9 aA aB aC aD aE aF
That was last week. Today's is in gnuplot, which lets you write a braced pair of numeric literals and interprets them as the real and imaginary parts of a complex number. This is easy to find out even without looking in the manual, because it uses the same syntax on output if you do something that has a complex result: gnuplot> print {1,1}*{2,3} {-1.0, 5.0} gnuplot> print sqrt(-1) {0.0, 1.0}
But what you might not have expected, having discovered that, is that it only applies to numeric literals. You can't, for instance, do this: gnuplot> print {pi/2, 1.234} ^ invalid complex constant
That would be too easy, of course. Instead you must do something much more ugly, like this: gnuplot> print pi/2 + {0, 1.234} {1.5707963267949, 1.234}
And if you wanted a non-constant imaginary component too, I can only assume you'd be forced to fall back to writing the expression for the imaginary part, multiplying explicitly by {0,1}, and adding it to the expression for the real part. Bah! |