Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / fpc-devel / 2015-10

Fwd: While - Otherwise Statement

16 messages · 7 people · –

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

MohsenTi

Hi everybody

I add new feature to FPC compiler to simplify programming. this is While - Otherwise working like While - Else in python and has backwards compatibility.

Examples

Ex1: While (I<5) do begin Writeln(I); Dec(I); end otherwise
writeln('otherwise');
Ex2: While (I<5) do begin Writeln(I); Dec(I); break; end otherwise
writeln('otherwise');
Ex3: if (I<10) then While (I<5) do begin Writeln(I); Dec(I); break; end
otherwise writeln('otherwise') else writeln('else');

I attached a svn diff file to email and I'm going to add For-Otherwise and more.

please test it and let me know what you think.

mohsen

Reply by email

Sven Barth
to MohsenTi
"MohsenTi" wrote 5 lines
Hi everybody I add new feature to FPC compiler to simplify programming. this is While - Otherwise working like While - Else in python and has

backwards compatibility.

Nice idea with the otherwise. I first thought that this would break case-statements that use otherwise instead of else, but then I remembered that the case-label-blocks can and IMHO should be terminated by ; anyway. At least problems can be easily circumvented.

I don't know whether we'll add it to trunk, but I'll at least take a look at your code to give you feedback.

Oh, and please provide simple tests for your feature that could be added to our testsuite (in tests/test or tests/tbs) in case we decide to incorporate it.
Speaking of which: did you run the testsuite and compared the results to a run without modifications?
(If you need help with running the testsuite or interpreting the results, please ask, I have yet to write a wiki page for that...)

Regards,
Sven

Reply by email

Martin Frb
to Sven Barth
Sven Barth wrote 15 lines
Am 11.10.2015 15:56 schrieb "MohsenTi" < >: > > Hi everybody > > I add new feature to FPC compiler to simplify programming. > this is While - Otherwise working like While - Else in python and has backwards compatibility. Nice idea with the otherwise. I first thought that this would break case-statements that use otherwise instead of else, but then I remembered that the case-label-blocks can and IMHO should be terminated by ; anyway. At least problems can be easily circumvented.

"should", but they do not have to, at least not the last one before the otherwise

So if old code has

Show quoted text 6 lines
case a of 1 : write; 2: while a > 1 do a := a -1 otherwise write; end

that will break. (it can be fixed, but so could the if with while else.

why not a new keyword?

while bool do
foo()
afterwards [do] // or even "then" would make sense (from english reading perspective)

   bar();

Reply by email

MohsenTi
to Sven Barth: backwards compatibility. Nice idea with the otherwise. I first thought that this would…

I create 2 test files depends on testsuite readme file and make testsuite with make full command and set TEST_FPC variable to fpc ppcx64 compiler.

for-otherwise and while-otherwise diff file and test files attached to email.

test result :

Total = 6906 (75:6831)
Total number of compilations = 4264 (60:4204)
Successfully compiled = 3147
Successfully failed = 1057
Compilation failures = 55
Compilation that did not fail while they should = 5 Total number of runs = 2642 (15:2627)
Successful runs = 2627
Failed runs = 15
Number units compiled = 135
Number program that should not be run = 367
Number of skipped tests = 404
Number of skipped graph tests = 10
Number of skipped interactive tests = 31
Number of skipped known bug tests = 6
Number of skipped tests for other versions = 4
Number of skipped tests for other cpus = 190
Number of skipped tests for other targets = 163

I checked failed ones but it seems they are not related to my changes. What you think?

thanks a lot

Sven Barth wrote 32 lines
Am 11.10.2015 15:56 schrieb "MohsenTi" : > > Hi everybody > > I add new feature to FPC compiler to simplify programming. > this is While - Otherwise working like While - Else in python and has backwards compatibility. Nice idea with the otherwise. I first thought that this would break case-statements that use otherwise instead of else, but then I remembered that the case-label-blocks can and IMHO should be terminated by ; anyway. At least problems can be easily circumvented. I don't know whether we'll add it to trunk, but I'll at least take a look at your code to give you feedback. Oh, and please provide simple tests for your feature that could be added to our testsuite (in tests/test or tests/tbs) in case we decide to incorporate it. Speaking of which: did you run the testsuite and compared the results to a run without modifications? (If you need help with running the testsuite or interpreting the results, please ask, I have yet to write a wiki page for that...) Regards, Sven _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Reply by email

Sven Barth
to MohsenTi
"MohsenTi" wrote
I checked failed ones but it seems they are not related to my changes.

It's best you compare the faillist files in tests/output/cpu-os from an unmodified and a modified run. This way you can find out if you had any changes in the testsuite.

Also the testfiles /must/ start with a "t". I haven't yet looked at the code though (I'm a bit busy otherwise so it will take some time for me).

Regards,
Sven

Reply by email

Sven Barth
to Martin Frb: "should", but they do not have to, at least not the last one before the otherwise So if…
"Martin Frb" wrote 9 lines
On 11/10/2015 16:14, Sven Barth wrote: > > Am 11.10.2015 15:56 schrieb "MohsenTi" : > > > > Hi everybody > > > > I add new feature to FPC compiler to simplify programming. > > this is While - Otherwise working like While - Else in python and has

backwards compatibility.

> > Nice idea with the otherwise. I first thought that this would break

case-statements that use otherwise instead of else, but then I remembered that the case-label-blocks can and IMHO should be terminated by ; anyway. At least problems can be easily circumvented.

"should", but they do not have to, at least not the last one before the

otherwise

I know and that's something I'm probably going to be wondering about for all eternity -.-

why not a new keyword?

I'm not a fan of adding new keywords for something like this...

while bool do foo() afterwards [do] // or even "then" would make sense (from english reading

perspective)

bar();

That "then" is a great idea! That would definitely not break anything and it would make sense indeed:

=== code begin ===

while bool do
  foo
then
  bar;
repeat
  foo;
until bool then
  bar;

=== code end ===

Regards,
Sven

Reply by email

Tomas Hajny
to Sven Barth

On Sun, October 11, 2015 22:48, Sven Barth wrote:
.
.

Show quoted text 14 lines
That "then" is a great idea! That would definitely not break anything and it would make sense indeed: === code begin === while bool do foo then bar; repeat foo; until bool then bar; === code end ===

I'm afraid that I got lost in this discussion, but what exactly would be the supposed semantic difference between the behaviour compared to situation when there was a semicolon instead of 'then' there?

Tomas

Reply by email

Steve Smith
to Sven Barth: backwards compatibility. case-statements that use otherwise instead of else, but then I…
Sven Barth wrote 19 lines
That "then" is a great idea! That would definitely not break anything and it would make sense indeed: === code begin === while bool do foo then bar; repeat foo; until bool then bar; === code end === Regards, Sven

Am I being stupid? It's late here so...

What's wrong with....
=== code begin ===

while bool do
    foo;
bar;

or

repeat
    foo;
until bool;
bar;

=== code end ===

Reply by email

Steve Smith
to Steve Smith
Steve Smith wrote 43 lines
On 11/10/15 21:48, Sven Barth wrote: > That "then" is a great idea! That would definitely not break anything and it > would make sense indeed: > > === code begin === > > while bool do > foo > then > bar; > > repeat > foo; > until bool then > bar; > > === code end === > > Regards, > Sven Am I being stupid? It's late here so... What's wrong with.... === code begin === while bool do foo; bar; or repeat foo; until bool; bar; === code end === _______________________________________________ fpc-devel maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-devel

Oops... Sorry Tomas!

Reply by email

Martin Frb
to Tomas Hajny: . . I'm afraid that I got lost in this discussion, but what exactly would be the supposed…
Tomas Hajny wrote 21 lines
On Sun, October 11, 2015 22:48, Sven Barth wrote: . . > That "then" is a great idea! That would definitely not break anything and > it would make sense indeed: > > === code begin === > while bool do > foo > then > bar; > > repeat > foo; > until bool then > bar; > === code end === I'm afraid that I got lost in this discussion, but what exactly would be the supposed semantic difference between the behaviour compared to situation when there was a semicolon instead of 'then' there?

You mean compared to the otherwise solution?

The following is currently valid code:
case a of
   1: write;
   2: while a > 0 do dec(a)   // no semicolon
   otherwise
      write('a was neither 1 nor 2');
end;

This code would continue to compile, but it would change meaning/behaviour. So if somebody has code like that, in a million line project, which fails after otherwise was introduced, then it could be a long search for why it fails. (Easy to fix once found, but hard to find)

Besides "then" makes more sense (as in reading it as english description).

Both else/otherwise, to me read as: If the while block before was not otherwords
while a > 0 do write

   otherwise halt;

reads to me "halt" is an alternative to the "while". It gets executed if the while was never executde (a was already <= 0 when while was reached first)

"then" in english may mean "after that" and that is what happens here. After the while do something.

Reply by email

Sven Barth
to Steve Smith: Am I being stupid? It's late here so... What's wrong with.... === code begin === while…
"Steve Smith" wrote 20 lines
Am I being stupid? It's late here so... What's wrong with.... === code begin === while bool do foo; bar; or repeat foo; until bool; bar; === code end ===

You know... You got me there...
Though at least for the while-loop it may have a use if one defines the then-clause as being executed only if the loop was entered once. Or - using a different keyword - if the loop was never executed. The repeat-loop however is always executed at least once, so there it's completely useless indeed...

Regards,
Sven

Reply by email

Sven Barth
to Dmitry Boyarintsev: But has case-otherwise been in FPC from the start? I believe it came from GNU pascal (…

Am 12.10.2015 03:19 schrieb "Dmitry Boyarintsev" <

Show quoted text 7 lines
: a bit off-topic, But has case-otherwise been in FPC from the start? I believe it came from GNU pascal (

http://www.gnu-pascal.de/gpc/otherwise.html) and never existed in Delphi world (
http://docwiki.embarcadero.com/RADStudio/XE3/en/Declarations_and_Statements#Case_Statements) ?!

I can see that FPC compiles case-otherwise for any syntax mode.

It's from Extended ISO Pascal and I don't know for how long it exists in FPC already, but it does so definitely for some time.

Regards,
Sven

Reply by email

Dmitry Boyarintsev
to Sven Barth
Sven Barth wrote
It's from Extended ISO Pascal and I don't know for how long it exists in FPC already, but it does so definitely for some time.

Thanks! I've never thought to go and read the FP documentation on "case statement", assuming it works in turbo pascal/delphi compatible way.

About while-then. While the syntax is unlikely to break anything, it's inconsistent with if-statement.
where, if-then is executed when condition is true. For while-then is executed then condition is false. Thus, while-else or while-otherwise are better. However, both syntax would cause code incompatibility.

thanks,
Dmitry

Reply by email

Sven Barth
to Dmitry Boyarintsev

Am 12.10.2015 17:17 schrieb "Dmitry Boyarintsev" <

: About while-then. While the syntax is unlikely to break anything, it's

inconsistent with if-statement.

where, if-then is executed when condition is true. For while-then is executed then condition is false. Thus, while-else or while-otherwise are better. However, both syntax

would cause code incompatibility.

It's less about consistency with if-then, but more about consistency from a human language point of view.

"while true do this then that" reads more or less as well as "while true do this otherwise that" (though both carry a slightly different meaning) with the added benefit of the former not to break any existing code (as you had written yourself).

Regards,
Sven

Reply by email

Marco van de Voort
to Sven Barth: Am 12.10.2015 03:19 schrieb "Dmitry Boyarintsev" <…

In our previous episode, Sven Barth said:

Show quoted text 7 lines
world ( http://docwiki.embarcadero.com/RADStudio/XE3/en/Declarations_and_Statements#Case_Statements) ?! > I can see that FPC compiles case-otherwise for any syntax mode. It's from Extended ISO Pascal and I don't know for how long it exists in FPC already, but it does so definitely for some time.

Afaik from when mode macpas was added (CodeWarrior) by Olle and Jonas.

Reply by email