indexing tuples using strings

Bill Baxter wbaxter at gmail.com
Mon Dec 1 16:52:30 PST 2008


On Tue, Dec 2, 2008 at 9:39 AM, bearophile <bearophileHUGS at lycos.com> wrote:
> Bill Baxter:
>> Tuples have an annoying "auto-flattening" behavior which means that
>> it's difficult to create very advanced data structures out of them.
>
> This has to change in D2. Perl shows why that's bad.

My Perl is rusty.  What about Perl shows that auto-flattening is bad?

> To replace all the current semantics you can just to add a syntax that performs as an 'apply' (Python uses a * for this, but D probably needs a different syntax).

Yeh, probably this is the idea that comes to anyone familiar with
Python.  Preserve the packaging of a tuple by default, require some op
to "explode" the contents back out into a list.  But then that

> Time ago I have created some machinery to represent arbitrarily nested "arrays" into a tuple, using an encoding that can represent all the lengths of the sub-sub-sub-etc "arrays", but it's complex, and probably uses too much resources during compile-time, so something more native is better.

Isn't there an easier way to fake it using structs?  Like
template Tuple(T...) { alias T Tuple }
struct STuple(T...) { alias T tuple; }

alias Tuple!(STuple(int,float), STuple(string,double), int, creal)
CantFlattenThis;

And you can write flatteners and nesters for that.  Seems like fun,
maybe I'll waste a few minutes working on that. :-)

--bb



More information about the Digitalmars-d mailing list