Multiple Tuple IFTI Syntactic Sugar

dsimcha dsimcha at yahoo.com
Sun Feb 1 12:51:23 PST 2009


I've been thinking about how IFTI works for variadic function templates.  I
use variadic functions heavily in the infotheory module of dstats, and am
looking to add some features here.  Currently, my mutual information function
looks like:

real mutualInfo(T, U)(T[] x, U[] y);

I'd like to generalize this so that both x and y can be any number of vectors,
yielding in standard mathematical notation, something like I(x, y; z, a),
which is the mutual information of (x, y) as a joint distribution with (z, a)
as a joint distribution.  However, trying to turn this into D code with decent
notation leads to some headaches:

real mutualInfo(T..., U...)(T x, U y);

If I call this as something like:  mutualInfo(x, y, z, a), this is obviously
ambiguous.  If I explicitly instantiate one of the tuples (assuming bug 2599
gets fixed), then this leads to some rather horrible looking notation.  If I
only use one big tuple, I have to pass in an extra parameter to indicate the
boundary between x and y, again making the notation quite ugly.

Would it be possible to add some feature where I could call mutualInfo(x, y;
z, a) or mutualInfo(x, y: z, a) or something?  The idea is that some delimiter
other than the comma would indicate what the boundaries are between two
variadic parameters.  Is this reasonable or is it too much of a niche feature?



More information about the Digitalmars-d mailing list