DIP19: Remove comma operator from D and provision better syntactic support for tuples

Nick Sabalausky SeeWebsiteToContactMe at semitwist.com
Mon Sep 24 03:46:27 PDT 2012


On Mon, 24 Sep 2012 06:20:55 -0400
Nick Sabalausky <SeeWebsiteToContactMe at semitwist.com> wrote:

> On Mon, 24 Sep 2012 10:47:38 +0200
> "foobar" <foo at bar.com> wrote:
> > 
> > Nope.
> > One of the ways in math to "build" the positive numbers based on 
> > set theory is via singletons:
> > n := |tuple of empty tuples|
> > so "1" is defined as { {} } whereas "0" is simply {}. That does 
> > not work with the above suggestion. Now, I realize this is an 
> > arguably convoluted math example but it does show that the 
> > treating { {} } as {} is limiting the expressive power of tuples.
> > 
> 
> And int's are limiting compared to mathematical integers. So what?
> So ok, maybe this is limiting from a theoretical standpoint. But
> practically speaking? I dunno. We're not making tuples to emulate
> set theory here, we're just looking for ad-hoc anonymous structs.
> 
> Besides, I only said they were logically the same thing, not
> mechanically. I'm only suggesting that a one-element tuple be
> implicitly convertible to/from the type of its element. So there
> would likely still be the different types, it just makes sense that
> you should be able to use one as the other.
> 

I guess what I mean is: If you really need a strict separation between
a "tuple of one" and a non-tuple, then maybe it's an indication
that you're just using the wrong tool?

That said, I'm not necessarily opposed to the strict separation if we
had a good candidate for built-in tuple literal syntax. But *if* the
best we have is parens (and maybe there *is* something better?) then
maybe this would be an acceptable way to achieve it?

Ie:

// (3) is polysemous: Either int or (int)
int   a = (3);  // Normal value
(int) b = (3);  // One-element tuple
auto  c = (3);  // Default to normal "int"?

void foo(int z) {}
void foo((int) z) {}

void takeInt(int z) {}
void takeTuple((int) z) {}

foo(a); // Calls first overload
foo(b); // Calls second overload

takeInt(a); // ok
takeInt(b); // ok

takeTuple(a); // ok
takeTuple(b); // ok



More information about the Digitalmars-d mailing list