www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - What is a tuple and why should one care?

reply Justin Johansson <no spam.com> writes:
There's a lot of (imho, pointless) discussion going on about
tuples in D.

I've asked before and haven't any illumination, especially of Walter.

In the context of D, can someone please enlighten me as to exactly
what a tuple is supposed to be.

The discussion so far appears to me to be focusing on syntax
for these "tuple thing-a-m-be's" without defining what the bloody
thing-are-might-be's are.

Thanks in advance for zen enlightenment,
Justin Johansson
Oct 08 2010
next sibling parent Michel Fortin <michel.fortin michelf.com> writes:
On 2010-10-08 08:37:39 -0400, Justin Johansson <no spam.com> said:

 There's a lot of (imho, pointless) discussion going on about
 tuples in D.
 
 I've asked before and haven't any illumination, especially of Walter.
 
 In the context of D, can someone please enlighten me as to exactly
 what a tuple is supposed to be.
 
 The discussion so far appears to me to be focusing on syntax
 for these "tuple thing-a-m-be's" without defining what the bloody
 thing-are-might-be's are.
 
 Thanks in advance for zen enlightenment,
 Justin Johansson
D currently has two different kinds of tuple: the one in the language[1], which is created by variadic template arguments, and the one in the standard library[2], which is a struct wrapper for the first kind that addresses a couple of its shortcomings and adds named fields. My understanding is that Walter wants to improve the language tuple by making it possible to return one from a function and giving it a literal syntax while Andrei would prefer to continue using the library-based tuple. Personally, I'd prefer if we had only one kind of tuple because it makes discussions on this subject really confusing. [1]: http://www.digitalmars.com/d/2.0/template.html#TemplateTupleParameter [2]: http://www.digitalmars.com/d/2.0/phobos/std_typecons.html -- Michel Fortin michel.fortin michelf.com http://michelf.com/
Oct 08 2010
prev sibling next sibling parent Lutger <lutger.blijdestijn gmail.com> writes:
Justin Johansson wrote:

 There's a lot of (imho, pointless) discussion going on about
 tuples in D.
 
 I've asked before and haven't any illumination, especially of Walter.
 
 In the context of D, can someone please enlighten me as to exactly
 what a tuple is supposed to be.
 
 The discussion so far appears to me to be focusing on syntax
 for these "tuple thing-a-m-be's" without defining what the bloody
 thing-are-might-be's are.
 
 Thanks in advance for zen enlightenment,
 Justin Johansson
This is how I understand it: Most simply put, tuples are ordered and compile-time-indexable lists of 'template parameters' which may consist only of types, symbols and values (compile time constants). Out of templates with variadic parameters, tuple types of arbitrary length can be constructed. Furthermore, tuples can be constructed out of aggregate types with the .tupleof property. I think that's basically it: compile time lists of heterogeneous compile time things. More specifically the library phobos defines: - type tuples: consisting only of types (traits.isTypeTuple) - expression tuples: consisting only of values and symbols that refer to variables (traits.isExpressionTuple) - 'records': std.typecons.Tuple is basically a type that can create an instance of a type tuple with a convenient 'record' interface
Oct 08 2010
prev sibling parent Pelle <pelle.mansson gmail.com> writes:
On 10/08/2010 02:37 PM, Justin Johansson wrote:
 There's a lot of (imho, pointless) discussion going on about
 tuples in D.

 I've asked before and haven't any illumination, especially of Walter.

 In the context of D, can someone please enlighten me as to exactly
 what a tuple is supposed to be.

 The discussion so far appears to me to be focusing on syntax
 for these "tuple thing-a-m-be's" without defining what the bloody
 thing-are-might-be's are.

 Thanks in advance for zen enlightenment,
 Justin Johansson
Hello, this thing here that I don't understand is pointless. Tuples are ordered heterogeneous sequences of fixed length. They exist in std.typecons. What is proposed is a syntax for unpacking them. This has been proven useful in many languages, such as python and haskell.
Oct 08 2010