Sign in Join

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

Mailing lists / fpc-pascal / 2016-02

Re: if-then-else expression

17 messages · 8 people · –

Reply by email Subscribe to this list Your subscription

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

Sven Barth
Sven Barth wrote 10 lines
Hello together! Time for the next flame. I've attached a patch which implements an "if Condition then ThenExpr else ElseExpr"-expression for those that want to play around with it. It follows the same principles as the yet-to-be-renamed IfThen() (namely that the type is determined by the ThenExpr) as it's just a different syntax with the same (copy & pasted) code behind it... Note: this patch *might* also work with 3.0.0 or even 2.6.4...

And I just noticed that I sent this to fpc-devel instead of fpc-pascal... *sigh*

So here it is again for fpc-pascal as well.

Regards,
Sven

Maciej Izak
to Sven Barth

2016-02-01 21:16 GMT+01:00 Sven Barth :

On 01.02.2016 21:14, Sven Barth wrote: > Time for the next flame.

Flame? :O It was constructive discussion :)

For me

x := if true then 0 else 1

is ideal and compatible with Oxygene. +1 IMO no need to any other combination.

Maybe is time to start developing {$MODE OXYGENE} ?

Best regards, Maciej Izak
silvioprog
to Maciej Izak
Maciej Izak wrote 8 lines
2016-02-01 21:16 GMT+01:00 Sven Barth : > On 01.02.2016 21:14, Sven Barth wrote: > > Time for the next flame. Flame? :O It was constructive discussion :)

+1. It was constructive discussion.

For me

x := if true then 0 else 1

For me, no problem extending ObjFPC to make a new abbreviated Pascal language, however, will be IfThen() function kept? (or something like this)

Show quoted text 5 lines
is ideal and compatible with Oxygene. +1 IMO no need to any other combination. Maybe is time to start developing {$MODE OXYGENE} ?
Silvio Clécio
Michael Schnell
to Maciej Izak: 2016-02-01 21:16 GMT+01:00 Sven Barth : Flame? :O It was constructive discussion :) For me
Maciej Izak wrote
x := if true then 0 else 1

Here a keyword and a statement just optionally returns a value, Same is ignored in all legacy code but can be use it you want to and do know what you do.

Additionally "0" now is a statement, (optionally) extending what is considered a statement.

This is a rather drastic change in the basic definition of the language, but might be doable. I's completely optional, and I don't see how it might break anything.

But of course the paradigm would ask for being extended to many or all other keywords.

An obvious example is "case".

-Michael

Sven Barth
to Michael Schnell
Michael Schnell wrote 11 lines
On 02/01/2016 09:35 PM, Maciej Izak wrote: > > > x := if true then 0 else 1 Here a keyword and a statement just optionally returns a value, Same is ignored in all legacy code but can be use it you want to and do know what you do. Additionally "0" now is a statement, (optionally) extending what is considered a statement.

Why would "0" now be a statement? As long as the "if" is the expression as well then the definition would be "if Condition then ThenExpr else ElseExpr", not "if Condition then ThenStmt else ElseStmt". Otherwise things like procedures ore assignments would be allowed as well which is not the case.

This is a rather drastic change in the basic definition of the language, but might be doable. I's completely optional, and I don't see how it might break anything.

Of course it's doable. See the patch I attached at the initial mail of this thread.

Regards,
Sven

John Lee
to Sven Barth

So (Sven) to clarify, assume that your original ifthen [patch is now in latest svn compiler although more work will needed to do x:=if a then b else c;? j

Sven Barth wrote 33 lines
On 02.02.2016 10:25, Michael Schnell wrote: > On 02/01/2016 09:35 PM, Maciej Izak wrote: >> >> >> x := if true then 0 else 1 > > Here a keyword and a statement just optionally returns a value, Same is > ignored in all legacy code but can be use it you want to and do know > what you do. > > Additionally "0" now is a statement, (optionally) extending what is > considered a statement. Why would "0" now be a statement? As long as the "if" is the expression as well then the definition would be "if Condition then ThenExpr else ElseExpr", not "if Condition then ThenStmt else ElseStmt". Otherwise things like procedures ore assignments would be allowed as well which is not the case. > > This is a rather drastic change in the basic definition of the language, > but might be doable. I's completely optional, and I don't see how it > might break anything. Of course it's doable. See the patch I attached at the initial mail of this thread. Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Sven Barth
to John Lee
John Lee wrote
So (Sven) to clarify, assume that your original ifthen [patch is now in latest svn compiler although more work will needed to do x:=if a then b else c;? j

The IfThen() is in trunk though it will at least be renamed. The if-then-else expression would in theory be good to go as well. Just look at the first message of this thread for the patch to play around with it.

Regards,
Sven

geneb
to Sven Barth
Sven Barth wrote 10 lines
On 02.02.2016 20:22, John Lee wrote: > So (Sven) to clarify, assume that your original ifthen [patch is now in > latest svn compiler although more work will needed to do x:=if a then b > else c;? j The IfThen() is in trunk though it will at least be renamed. The if-then-else expression would in theory be good to go as well. Just look at the first message of this thread for the patch to play around with it.

I probably missed it, but what problem is "IfThen()" actually solving?

g.

Proud owner of F-15C 80-0007 http://www.f15sim.com - The only one of its kind. http://www.diy-cockpits.org/coll - Go Collimated or Go Home. Some people collect things for a hobby. Geeks collect hobbies. ScarletDME - The red hot Data Management Environment A Multi-Value database for the masses, not the classes. http://scarlet.deltasoft.com - Get it _today_!
John Lee
to Sven Barth: The IfThen() is in trunk though it will at least be renamed. The if-then-else expression…

Based on Florian's recent emails the if then else is ok, so guess we should be close to getting it all running. Great, thanks for your efforts. j

Sven Barth wrote 17 lines
On 02.02.2016 20:22, John Lee wrote: > So (Sven) to clarify, assume that your original ifthen [patch is now in > latest svn compiler although more work will needed to do x:=if a then b > else c;? j The IfThen() is in trunk though it will at least be renamed. The if-then-else expression would in theory be good to go as well. Just look at the first message of this thread for the patch to play around with it. Regards, Sven _______________________________________________ fpc-pascal maillist - http://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal
Dmitry Boyarintsev
to geneb: I probably missed it, but what problem is "IfThen()" actually solving? g. Proud owner of…

On Tue, Feb 2, 2016 at 4:07 PM, geneb wrote:

I probably missed it, but what problem is "IfThen()" actually solving?

It's a sugar syntax, for
if cond then
  x:= a
else
  x:=b;

Just follow this thread:
http://lists.freepascal.org/pipermail/fpc-pascal/2016-January/046375.html

Pro #1: shortness of script
Pro #2: easier porting of C-style code (with ternary ? operator. Pascal doesn't have an equivalent
https://en.wikipedia.org/wiki/%3F:#Programming_languages_without_the_conditional_operator )

thanks,
Dmitry

geneb
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 16 lines
On Tue, Feb 2, 2016 at 4:07 PM, geneb wrote: I probably missed it, but what problem is "IfThen()" actually solving? > > It's a sugar syntax, for if cond then x:= a else x:=b; Just follow this thread: http://lists.freepascal.org/pipermail/fpc-pascal/2016-January/046375.html Pro #1: shortness of script Pro #2: easier porting of C-style code (with ternary ? operator. Pascal

So it's not solving a /problem/ it's lessening an inconvienence(sp!).

I would've gone with IIf(). :)

g.

Proud owner of F-15C 80-0007 http://www.f15sim.com - The only one of its kind. http://www.diy-cockpits.org/coll - Go Collimated or Go Home. Some people collect things for a hobby. Geeks collect hobbies. ScarletDME - The red hot Data Management Environment A Multi-Value database for the masses, not the classes. http://scarlet.deltasoft.com - Get it _today_!
Dmitry Boyarintsev
to geneb
geneb wrote
So it's not solving a /problem/ it's lessening an inconvienence(sp!). I would've gone with IIf(). :)

Just keep in mind that the thread (about preferences) is closed. Everyone are welcomed to create poll on the forum. Discussion also goes on at fpc-other list.

thanks,
Dmitry

geneb
to Dmitry Boyarintsev
Dmitry Boyarintsev wrote 8 lines
On Tue, Feb 2, 2016 at 4:40 PM, geneb wrote: > So it's not solving a /problem/ it's lessening an inconvienence(sp!). > > I would've gone with IIf(). :) > Just keep in mind that the thread (about preferences) is closed.

You can't "close" a discussion thread on an email list. :)

Everyone are welcomed to create poll on the forum. Discussion also goes on at fpc-other list.

I don't have a dog in the fight, I was just making an observation.

g.

Proud owner of F-15C 80-0007 http://www.f15sim.com - The only one of its kind. http://www.diy-cockpits.org/coll - Go Collimated or Go Home. Some people collect things for a hobby. Geeks collect hobbies. ScarletDME - The red hot Data Management Environment A Multi-Value database for the masses, not the classes. http://scarlet.deltasoft.com - Get it _today_!
Sven Barth
to geneb
"geneb" wrote 13 lines
On Tue, 2 Feb 2016, Dmitry Boyarintsev wrote: > On Tue, Feb 2, 2016 at 4:40 PM, geneb wrote: > >> So it's not solving a /problem/ it's lessening an inconvienence(sp!). >> >> I would've gone with IIf(). :) >> > > Just keep in mind that the thread (about preferences) is closed. You can't "close" a discussion thread on an email list. :)

Yes, you can, because mails towards the list can be set to be moderated based on different criteria and I bet that the thread ID is one of them. Jonas (as list admin) probably did just that.

Regards,
Sven

geneb
to Sven Barth
Sven Barth wrote
Yes, you can, because mails towards the list can be set to be moderated based on different criteria and I bet that the thread ID is one of them. Jonas (as list admin) probably did just that.

Mailman (at least version 2.1.20, which is what I run) doesn't work like that.

g.

Proud owner of F-15C 80-0007 http://www.f15sim.com - The only one of its kind. http://www.diy-cockpits.org/coll - Go Collimated or Go Home. Some people collect things for a hobby. Geeks collect hobbies. ScarletDME - The red hot Data Management Environment A Multi-Value database for the masses, not the classes. http://scarlet.deltasoft.com - Get it _today_!
Flávio Etrusco
"geneb" wrote 10 lines
(...) So it's not solving a /problem/ it's lessening an inconvienence(sp!). I would've gone with IIf(). :) g.

The problem with Iff() is:
1) it either retains normal function behavior and thus has to evaluate both expressions (i.e. suboptimal performance and allowing side effects);
2) or add inconsistency by using function syntax but different behavior.

Best regards,
Flávio

silvioprog
to Flávio Etrusco

etrusco wrote

Show quoted text 9 lines
On Feb 2, 2016 7:41 PM, "geneb" < geneb@ > wrote: [...] The problem with Iff() is:1) it either retains normal function behavior and thus has to evaluate both expressions (i.e. suboptimal performance and allowing side effects);
Well:
program Project1;  function test1: integer;  begin    WriteLn('A');
Result := 10;  end;  function test2: integer;  begin    WriteLn('B');
Result := 20;  end;  function CommonFunc(A: Boolean; B, C: integer):
integer;  begin    if A then      Result := B    else      Result := C;
end;var  X: LongInt;begin  X := IfThen(True, test1, test2);  WriteLn(X);
WriteLn('----');  X := CommonFunc(True, test1, test2);  WriteLn(X);
ReadLn;end.
Result:
A10----BA10
View this message in context: http://free-pascal-general.1045716.n5.nabble.com/Re-if-then-else-expression-tp5723834p5723966.html Sent from the Free Pascal - General mailing list .