DIP32: Uniform tuple syntax

Timon Gehr timon.gehr at gmx.ch
Fri Mar 29 06:20:58 PDT 2013


On 03/29/2013 09:57 AM, kenji hara wrote:
> http://wiki.dlang.org/DIP32
>
> Kenji Hara

Looks quite nice. I especially like the {a, b} => ... thing.

I think, however, that there are a handful serious flaws that need to be 
addressed:

0 "Inside tuple literal, ; never appears."
   {{;}}           // a tuple not matching your specification
   {{if(foo()){}}} // a non-tuple matching your specification

1 "Note: Cannot swap values by tuple assignment."
   IMO a no-go. The syntax is too accessible to introduce this kind of
   pitfall.

2 "// Error: cannnot use $ inside a function literal"
   That's a DMD-ism presumably stemming from laziness during "fixing" of
   an ICE/wrong code bug or something. I'd hate to carry this over to
   the spec. Don't rely on it. The disambiguation is arbitrary, but may
   be necessary. (It's not like it is a case actually occurring in real
   code.)

3 Unpacking / pattern matching is underspecified.
   - Do patterns nest?
   - Which right-hand sides are allowed with which semantics?
   - Which left-hand sides are allowed with which semantics?
     eg, what about:
       ref int foo() { ... }
       { foo(), foo() } = {1, 2};

4 There is no way to capture the part matched by "..."

5 .expand (or similar) property is missing.

6 Relation to {a: 2, b: 3}-style struct literals not explained.

7 Tuple unpacking for template parameters not mentioned.


Is there a migration path for Phobos tuples planned?

Eg. template Tuple(T...){ alias Tuple = {T}; }
     (field spec parsing left out for illustration)


More information about the Digitalmars-d mailing list