DIP32: Uniform tuple syntax

Simen Kjærås simen.kjaras at gmail.com
Fri Mar 29 06:13:28 PDT 2013


On Fri, 29 Mar 2013 09:57:51 +0100, kenji hara <k.hara.pg at gmail.com> wrote:

> http://wiki.dlang.org/DIP32

Good stuff! I agree with Andrej Mitrovic that 'if (auto {1, y} = tup)'
looks a tad weird, and 'if (auto {$x, y} = coord)' is even worse.

Frankly, I feel 'if' is the wrong vessel for pattern matching. Switch/case
is perfect. It reads sensibly, and there is no confusion of assignment and
comparison operators.


....Perhaps what's needed is simply a different operator:

if (auto {1, y} : tup)
if (auto {$x, y} : tup)

That feels more sensible to me. Mayhap : is not the best choice, but =
feels wrong to me. I'm sure I could get used to it, but it seems to me that
the return value of 'auto {1, y} = tup' should be a tuple, not a boolean
value.

The $ still feels weird, but I'm all out of better ideas.


All in all, I really like this, but agree with bearophile that some parts
may be better left for a future DIP. For now, unpacking and switch pattern
matching would be awesome.

-- 
Simen


More information about the Digitalmars-d mailing list