else and otherwise in a case statement

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

else and otherwise in a case statement

Mark Morgan Lloyd-5
I've been doing a bulk replace of 'case..else' to 'case..otherwise' to
eliminate possible ambiguities that have bitten me in the past, and have
noticed something interesting under 2.6.4 on x86 Linux.

This is OK:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   else
                   end;

This is an error:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   otherwise
                   end;

I can fix it like this:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted: ;
                   otherwise
                   end;

But that grates since I was brought up on ; being a statement separator
rather than a terminator. Alternatively this is OK:

         Ord('.'): case shiftState of
                     unshifted: mechCode := Corr_88_Period;
                     shifted:
                   end;

but I like having the regular code (in some cases there are active
otherwise clauses, and I spent enough time with Modula-2 to prefer
enumerating all possibilities).

Is this difference expected, and what is the best workaround?

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: else and otherwise in a case statement

Howard Page-Clark
On 11/12/2014 21:07, Mark Morgan Lloyd wrote:
> I've been doing a bulk replace of 'case..else' to 'case..otherwise' to
> eliminate possible ambiguities that have bitten me in the past, and have
> noticed something interesting under 2.6.4 on x86 Linux.

How can "else" be ambiguous within a case statement?

Howard


---
This email has been checked for viruses by Avast antivirus software.
http://www.avast.com

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: else and otherwise in a case statement

Ewald-2
On 12/11/2014 11:13 PM, Howard Page-Clark wrote:
> On 11/12/2014 21:07, Mark Morgan Lloyd wrote:
>> I've been doing a bulk replace of 'case..else' to 'case..otherwise' to
>> eliminate possible ambiguities that have bitten me in the past, and have
>> noticed something interesting under 2.6.4 on x86 Linux.
>
> How can "else" be ambiguous within a case statement?

If one omits the trailing semicolon (the one that's commented), the else
becomes ambiguous:

Case Something of
    Value1: ;
    Value2: If Condition Then DoSomething (*;*)
Else
End;


--
Ewald

_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Reply | Threaded
Open this post in threaded view
|

Re: else and otherwise in a case statement

Mark Morgan Lloyd-5
Ewald wrote:

> On 12/11/2014 11:13 PM, Howard Page-Clark wrote:
>> On 11/12/2014 21:07, Mark Morgan Lloyd wrote:
>>> I've been doing a bulk replace of 'case..else' to 'case..otherwise' to
>>> eliminate possible ambiguities that have bitten me in the past, and have
>>> noticed something interesting under 2.6.4 on x86 Linux.
>> How can "else" be ambiguous within a case statement?
>
> If one omits the trailing semicolon (the one that's commented), the else
> becomes ambiguous:
>
> Case Something of
>     Value1: ;
>     Value2: If Condition Then DoSomething (*;*)
> Else
> End;

Yes, that's the one. When I raised it it was pointed out to me that the
  otherwise  form was intended as a drop-in replacement to avoid this.

--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]
_______________________________________________
fpc-pascal maillist  -  [hidden email]
http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal