http://d.puremagic.com/issues/show_bug.cgi?id=596



--- Comment #4 from bearophile_h...@eml.cc 2011-01-30 06:37:06 PST ---
(In reply to comment #3)

> struct Foo { int x, y; }
> void main() {
>     auto f = Foo(1, 2);
>     int f;
>     switch (f) {
>         case Foo(1, _): break; // all structs where x==1, y == don't care
>         default: break;
>     }
> }

The idea of wildcards is very useful, it turns the D switch into something
useful to partially match Tuples too. This is a very commonly used operation in
functional languages. But probably the "_" (underscore) is not right as
wildcard, because while it's nice and clear, it's a legal variable name.
Possible alternatives are a single &, or @ or %:

case Foo(1, &): break;
case Foo(1, @): break;
case Foo(1, %): break;

Or maybe just "void", that is longer, but adds no new tokens and is more clear
than an arbitrary symbol:


import std.typecons: Tuple;
alias Tuple!(int, "x", int, "y") Foo;
void main() {
    auto f = Foo(1, 2);
    switch (f) {
        case Foo(1, void): break; // any Foo with x==1, don't care y
        default: break;
    }
}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------

Reply via email to