Expression switch - an alternate proposal

Stephen Colebourne scolebourne at joda.org
Tue Apr 10 20:59:20 UTC 2018


On 10 April 2018 at 09:02,  <forax at univ-mlv.fr> wrote:
>>> Basically, your proposal is to use -> eveywhere, i think i prefer the opposite,
>>> do not use arrow at all.

Current Oracle proposal:
statements = colon
expression = colon, with arrow for expressions

Alternate proposal:
statements = colon
expression = symbol-that-isnt-colon

Remi proposal:
statements = colon
expression = colon

If the goal is a unified switch expression, Remi proposal wins. It is
dead simple and very consistent.

>> This is a reasonable alternative, but I don't think it would be very
>> popular.  I think people will really love being able to write:
>>
>>     case MONDAY -> 1;
>>     case TUESDAY -> 2;
>>
>> and will be sad if we make them write
>>
>>     case MONDAY: break 1;
>>     case TUESDAY: break 2;

Meh. Three more characters.

Yet:
- Avoids the arrow having a conflict of meaning with lambda.
- No mixed arrows & colons
- Much more consistent.
- Minimal change from existing switch.
- Less to learn.
Win, win, win.

So while I'd still choose to have a separate symbol for expression and
statement switches (because of my #1 goal), I'm also pretty fine with
the Remi proposal (because my #2 goal).

In fact, what the discussion has informed me is that my #1 and #2
goals are the wrong way around. Getting rid of the mixed arrows and
colons is now more important to me than understanding the context in a
large switch.

Stephen


More information about the amber-dev mailing list