Kray-G/kinx

Syntax conflict with `switch-else`.

Kray-G opened this issue · 6 comments

Now we can not write the code below because it is conflict between if and else.

switch (a) {
when 10:
    if (b) {
         /* */
    }
else:  // => Syntax error.
    /* something */
}

This is a restriction so far, but it should be solved if possible.

I am now planning it could be the otherwise keyword.
It will be used not only with switch-when but also case-when.

IMO, one of objective in this project is "like C syntax". so, I think default is good too.

Thanks for the comment!

default has been already used and it works with fall through.
else was introduced instead of default and it expects to work without fall through.

The problem is, that we need something like default without fall through, so else was introduced, but the name is not good for the situation.

That is why I come up with the otherwise keyword.
This keyword seems to be used in MATLAB.

I see. I had forgotten keywords related fall through😂

refs: 65139b1

Now you can write it like the following.

switch (a) {
when 10:
    if (b) {
         /* */
    }
otherwise:
    /* something */
}

And also you can still use else, but I may make it deprecated in the future.