Hello, has Lazarus (CodeTools) or FPC some checking for empty commands? I accidentally did this stupid mistake:
if ... then
begin
...
end else;
begin
...
exit;
end;
Note the semicolon behind the "else".
Semicolon as an empty command is sometimes useful (temporary solution).
Thanks, V.
Mailing lists / lazarus / 2017-01
Semicolon checking
5 messages · 5 people · –
- DDougC 1
- LLars 1
- MMark Morgan Lloyd 1
- MMartin Frb 1
- VVojtěch Čihák 1
Reply by email Subscribe to this list Your subscription
Read-only archive. Use j and k to move between messages.
VojtÄch Äihák wrote 10 lines
Yikes! I think you just discovered a bug in the pascal language itself that was not thought of... as when using a text editor it's easy to leave a semi colon laying around by accident some times.
I wonder if Oberon solves this issue, or semi-colon-less languages have any advantage. If you remove the begin from a language (Wirth did in his later languages) you get rid of some issues.
Lars wroteOn Sun, January 15, 2017 3:30 pm, VojtÄch Äihák via Lazarus wrote:> Hello, has Lazarus (CodeTools) or FPC some checking for empty commands? I> accidentally did this stupid mistake: > if ... then begin>> end else;> begin> ...> exit;> end;> Yikes! I think you just discovered a bug in the pascal language itselfthat was not thought of... as when using a text editor it's easy to leavea semi colon laying around by accident some times. I wonder if Oberon solves this issue, or semi-colon-less languages haveany advantage. If you remove the begin from a language (Wirth did in hislater languages) you get rid of some issues.-- _______________________________________________Lazarus mailing ://lists.lazarus-ide.org/listinfo/lazarus
It's one of a number of known nasties in the language definition. This is controversial, but Pascal was defined with ; being a /separator/ not a /terminator/, so strictly a semicolon is not needed before end else until etc. and in my experience only using it where necessary is a good habit to get into ( ;until was a syntax error in at least some versions of Turbo Pascal).
One other thing that helps in a very small way is to use case-otherwise-end rather than case-else-end, since it reduces the number of ambiguities.
Apart from that Wirth deserves no credit at all for leaving the dangling-else ambiguity in Pascal when it had been recognised and eliminated in ALGOL-68.
I expect to get kicked for all of the above. They are my opinions only, and might not be aligned with e.g. the coding style expected in patches submitted to the FPC or Lazarus projects.
I'm not going to kick you, Mark, as your comments are spot on.
What I think wold be very helpful to the FPC community is a warning that is issued when a semi-colon is immediately followed by a "begin" as that is an unusual construct and, as shown in the example here, an indicator of a likely mistake.
Doug C.
---- On Mon, 16 Jan 2017 03:27:25 -0500 Mark Morgan Lloyd via Lazarus <> wrote ----
On 16/01/17 07:30, Lars via Lazarus wrote:
> On Sun, January 15, 2017 3:30 pm, VojtÄch Äihák via Lazarus wrote:> Hello, has Lazarus (CodeTools) or FPC some checking for empty commands? I> accidentally did this stupid mistake: > if ... then begin>> end else;> begin> ...> exit;> end;>> Yikes! I think you just discovered a bug in the pascal language itselfthat was not thought of... as when using a text editor it's easy to leavea semi colon laying around by accident some times.
> I wonder if Oberon solves this issue, or semi-colon-less languages haveany advantage. If you remove the begin from a language (Wirth did in hislater languages) you get rid of some issues.-- _______________________________________________Lazarus mailing ://lists.lazarus-ide.org/listinfo/lazarus
It's one of a number of known nasties in the language definition. This
is controversial, but Pascal was defined with ; being a /separator/ not
a /terminator/, so strictly a semicolon is not needed before end else
until etc. and in my experience only using it where necessary is a good
habit to get into ( ;until was a syntax error in at least some versions
of Turbo Pascal).
One other thing that helps in a very small way is to use
case-otherwise-end rather than case-else-end, since it reduces the
number of ambiguities.
Apart from that Wirth deserves no credit at all for leaving the
dangling-else ambiguity in Pascal when it had been recognised and
eliminated in ALGOL-68.
I expect to get kicked for all of the above. They are my opinions only,
and might not be aligned with e.g. the coding style expected in patches
submitted to the FPC or Lazarus projects.
DougC wrote 7 lines
Well you can set the IDE to highlight such cases. (At least so long as the ; is on the same line, and right after the else)
In Options / Editor / go to "user defined markup" (F1 should get the wiki help)
Add a new term. Add the words
then;
then ;
else;
else ;and if you want with several spaces too.
Then set the background color to a strong red. Et voila.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus-ide.org/pipermail/lazarus/attachments/20170116/8d240ca5/attachment.html>
