DIP32: Uniform tuple syntax

Timothee Cour thelastmammoth at gmail.com
Sat Mar 30 01:55:04 PDT 2013


not 'open', there is already something called .expand property

http://forum.dlang.org/thread/fdkalkzhchuerkqlpzkg@forum.dlang.org

how about this:
auto x = {1,2,3};
auto x2 = {1,2};
assert(x[0..2]==x2);//no expansion
void fun(int x, int y);
fun(x2.expand);
fun(x[0..2].expand);

keeps slicing orthogonal from expansion

> On Fri, Mar 29, 2013 at 10:31 AM, Timon Gehr <timon.gehr at gmx.ch> wrote:
>> On 03/29/2013 05:39 PM, kenji hara wrote:
>>>
>>> 2013/3/30 bearophile <bearophileHUGS at lycos.com
>>> <mailto:bearophileHUGS at lycos.com>>
>>>
>>>
>>>     kenji hara:
>>>
>>>
>>>         I think it will become reasonable. If you really want re-packing
>>>         tuple, you
>>>         can use {tup[0..1]}. It's quite handy.
>>>
>>>
>>>     This is a bad idea. It is not handy and it introduces a special
>>>     case. Explicit is better than implicit.
>>>
>>>
>>> That is "explicit".  In D, opened tuple (currently it's generated from
>>> template parameters, e.g. std.typetuple.TypeTuple) and closed tuple
>>> (currently created by structs with alias tuple_field this; e.g.
>>> std.typecons.Tuple) are distinct. Slice operator always returns opened
>>> tuple.
>>
>>
>> Because of prior language limitations, not because it makes any sense!
>>
>> Current operator overloading limitations mandate that it is simply not
>> possible to create a Phobos tuple with a sane slice operator.
>>
>>> If tup[0..1] makes closed tuple implicitly, you cannot make new
>>> flattened tuple from other tuples.
>>>
>>> auto x = {1,"hi"};
>>> auto y = {[1,2], S(1)};
>>> auto tup1 = {x[], y[]};   // creates {1,"hi", [1,2], S(1)}
>>> auto tup2 = {x, y};   // creates {{1,"hi"}, {[1,2], S(1)}}
>>>
>>> Under your semantics, it is impossible.
>>> ...
>>
>>
>> Certainly not. Creating opened tuples from closed ones is not an operation
>> necessarily tied to slicing.
>>
>> Making an opened tuple should be an explicit operation on closed tuples.
>> Slicing and opening are orthogonal operations.
>>
>> auto tup1 = {x.open, y.open}; // creates {1,"hi", [1,2], S(1)}
>> auto tup2 = {x[0..2], y[]}; // creates {{1,"hi}, {[1,2], S(1)}}
>>
>> auto tup3 = {x[0..2].open, y[].open}; // creates {1,"hi", [1,2], S(1)}


More information about the Digitalmars-d mailing list