Replies: 3 comments 9 replies
-
I want the feature of var x = case [y, z]
when [1, _]: 1
when [2, _]: 10
when [v, 0]: {
return v + 42;
}
default: // or `else` keyword
0
; |
Beta Was this translation helpful? Give feedback.
-
ConclusionOverviewI have implemented this feature as suited with a current supported feature,
Related UpdatesBefore I implemented this feature, I tried that a pattern matching mechanism is applied to declaration statement first.
See documents described in References section for details. ReferencesFinally, I wrote a specification for this feature at a document below.
If you have any problem, please let me know. Thank you very much. |
Beta Was this translation helpful? Give feedback.
-
I updated
If you have any problem, feel free to let me know. |
Beta Was this translation helpful? Give feedback.
-
I try to start discussion about some future features.
Introduction
Thankfully according to increasing stars and visited by a lot of people, I am often asked about
break
inswitch-case
.This is a design decision by following meanings, but I also sometimes think that I would like to solve this issue.
break
inswitch-case
feels me the line will be connected to the next case. I imagine almost all C programmers will feel like that.How do you think about it?
Consideration
That is why, I considered the following 2 solutions.
break
should be necessary, butfallthrough
keyword will be introduced and it is also necessary when it is fall through.case-when
instead ofswitch-case
.switch-case
will be stayed the same.Conclusion
I am now planning to introduce
case-when
syntax for this.Although
switch-case
is a statement, I thnk to makecase-when
be as an expression.Therefore, if you write multiple statements in
when
clause, I assume that you will have to write a callback function.Maybe the arguments of that function will be values specified of
case
andwhen
.How about this?
Whatever you accept this or not, I am glad if giving me a feedback.
Of course I will be welcome if you have any other ideas.
Beta Was this translation helpful? Give feedback.
All reactions