On 9/23/12 5:57 PM, deadalnix wrote:
Le 23/09/2012 23:52, Nick Sabalausky a écrit :
Ok, here's a crazy idea:

Do the reasons for explicit tuple-expansion necessarily apply to
zero- and one-element tuples? I'm not so sure. Suppose we allowed
implicit expansion on those...

Now I know what you're thinking: That would be an ugly inconsistency
between tuples of sizes>1 vs<=1. Well, *mechanically* yes, but
consider this:

*Logically* speaking, is there really any difference between a
one-element tuple and an ordinary single value? I don't think so, and
here's why: What is a tuple, logically speaking? Multiple values being
handled as if they were a single value. So what's a one-element tuple?
*One* value being handled as if it were one value - which is *is*.

Similarly, a zero-element tuple is logically equivalent to void (or the
one value a void can have: the value void, a concept which has been
argued in the past that might be useful for D, particularly in
metaprogramming). (I admit this is a little weaker than my argument
for one-element tuples.)

So perhaps zero- and one-element tuples should be implicitly
convertible back and forth with void and ordinary non-tuple values,
respectively (polysemous values?), because that's what they essentially
are.


My reflection on the subject for the past month lead me to the same
conclusion.

This notion a lot of trouble with it; I think it's safe to abandon it entirely.

Once a one-element tuple becomes equivalent to the actual item, there's an explosion of trouble and special cases in the language and in code that uses it. For example, divide and conquer code that manipulates tuples and takes t[0 .. $/2] and t[$/2+1 .. $] would suddenly get to cases in which the slices are no longer tuples, and so on. And that's only the beginning.

Also, having no integrated notion of a zero-element tuple would again mess with the algebra as much as the absence of 0 would hurt numbers. It's just troublesome.

I appreciate the attraction of this idea, but again I think it's safe to just not even discuss it.


Andrei

Reply via email to