DIP19: Remove comma operator from D and provision better syntactic support for tuples
bearophile
bearophileHUGS at lycos.com
Wed Sep 26 15:38:35 PDT 2012
Jonathan M Davis:
> It sounds to me like the reason that structural typing is
> needed is because
> Tuple allows you to name its fields, which I've always thought
> was a bad idea,
I have appreciated named fields of D tuples since the beginning,
I have found them quite handy. With them sometimes you don't need
to unpack a tuple, you can just access its fields with a nice
name, avoiding to move around more than one variable.
In Python there are build-in tuples, and there is a
library-defined tuple type that supports names for its fields, it
even contains its name, so when you print one of them, it's able
to offer a nice textual representation:
>>> from collections import namedtuple
>>> Point = namedtuple('Point', 'x y')
>>> Point(5, 10)
Point(x=5, y=10)
Bye,
bearophile
More information about the Digitalmars-d
mailing list