gvanrossum / patma

Pattern Matching
1.03k stars 65 forks source link

Case goto's? #174

Closed Arthurdw closed 3 years ago

Arthurdw commented 3 years ago

Hey there. First of all, I want to say that this is absolutely amazing, but I was wondering how case goto's are planned?

Like what can be done in c#, ts etc

For example in c#:

switch (value) {
    case myEnum.A:
    case myEnum.B:
        // ...
        break;
    case myEnum.C:
        // ...
        break;
    case myEnum.D:
        // ...
        goto case myEnum.C;
    default:
        // ...
        break;
};
thautwarm commented 3 years ago

C# just reports an error when you jump to somewhere with incorrect scope(required variable binding can be missing), but in Python this sort of problems will be more difficult to control. And if you do have some common code block to execute after some cases, it will be more readable to call a function.