Recent

Author Topic: IfThen function  (Read 3749 times)

PascalDragon

  • Hero Member
  • *****
  • Posts: 4137
  • Compiler Developer
Re: IfThen function
« Reply #45 on: May 03, 2022, 01:26:10 pm »
The issue is this:

Quote
When the ArrayOperators modeswitch is in effect:
{$modeSwitch ArrayOperators}

then the + operator cannot be overloaded on dynamic arrays, because it is handled internally by the compiler.

which is currently at 15.2 of the reference manual: it would- IMO- be highly desirable to remove that so that addition of arrays could be overloaded, while still having a shortcut for concatenation of arrays and strings... and it would be reasonable IMO for that shortcut to not be overloadable since it is basically syntactic sugar.

We can not remove this, because it's required for Delphi. That's why it was introduced in the first place. Also this has now been part of two releases and wasn't merely part of the development branch, which means this is now part of backwards compatibility.

MarkMLl

  • Hero Member
  • *****
  • Posts: 4444
Re: IfThen function
« Reply #46 on: May 03, 2022, 02:13:18 pm »
We can not remove this, because it's required for Delphi. That's why it was introduced in the first place. Also this has now been part of two releases and wasn't merely part of the development branch, which means this is now part of backwards compatibility.

I didn't say remove it. I said that it would be desirable if there were an alternative, so that if the ArrayOperators modeswitch is in not effect it is possible to override + to be an addition operator while still having a concise concatenation operator.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

PascalDragon

  • Hero Member
  • *****
  • Posts: 4137
  • Compiler Developer
Re: IfThen function
« Reply #47 on: May 04, 2022, 09:33:16 am »
We can not remove this, because it's required for Delphi. That's why it was introduced in the first place. Also this has now been part of two releases and wasn't merely part of the development branch, which means this is now part of backwards compatibility.

I didn't say remove it. I said that it would be desirable if there were an alternative, so that if the ArrayOperators modeswitch is in not effect it is possible to override + to be an addition operator while still having a concise concatenation operator.

One doesn't need an operator for everything and the kitchen sink. Just use Concat and be done with it.

MarkMLl

  • Hero Member
  • *****
  • Posts: 4444
Re: IfThen function
« Reply #48 on: May 04, 2022, 10:11:16 am »
One doesn't need an operator for everything and the kitchen sink. Just use Concat and be done with it.

Speaking as somebody who has sold lots of compilers for different languages, I'd suggest that Pascal's robust string support in particular reliable handling of + as the string concatenation operator was a very big factor in its erstwhile success.

Make that more difficult to use, without providing a concise alternative, and it's yet another nail in the language's coffin.

And I fully appreciate that this isn't entirely FPC's doing, and that a lot of the responsibility for (arguably) messing things up rests with Borland's successors. But their interest is primarily in having a tool for their own use and in milking a commercial market, while FPC/Lazarus are the standard bearers in trying to keep the language alive and relevant.

I'm sorry if that appears unnecessarily harsh. But the fact of the matter is that no number of sexy modern "computer-sciency" extensions will compensate for screwing up the underlying philosophy of the language as thrashed out by Wirth, UCSD and Borland in their early days, and I'm sure that I'm not the only user embittered by having spent far too much time fiddling with it rather than following popular opinion- and the jobs market.

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

Thaddy

  • Hero Member
  • *****
  • Posts: 11628
Re: IfThen function
« Reply #49 on: May 05, 2022, 05:39:24 pm »
I added - and it was accepted - a patch for a generic ifthen() years ago. It is for sure in 3.2.0 but it may be even 3.0.4.
Michael merged it.
Black themes should be banned.

MarkMLl

  • Hero Member
  • *****
  • Posts: 4444
Re: IfThen function
« Reply #50 on: May 05, 2022, 06:20:50 pm »
I added - and it was accepted - a patch for a generic ifthen() years ago. It is for sure in 3.2.0 but it may be even 3.0.4.
Michael merged it.

But is that an IfThen() function (i.e. the parameters are both evaluated) or a statement (i.e. only one expression out of two is evaluated)?

MarkMLl
MT+86 & Turbo Pascal v1 on CCP/M-86, multitasking with LAN & graphics in 128Kb.
Pet hate: people who boast about the size and sophistication of their computer.
GitHub repositories: https://github.com/MarkMLl?tab=repositories

tt

  • Jr. Member
  • **
  • Posts: 69
Re: IfThen function
« Reply #51 on: May 06, 2022, 12:23:32 pm »
I added - and it was accepted - a patch for a generic ifthen() years ago. It is for sure in 3.2.0 but it may be even 3.0.4.
Michael merged it.

But is that an IfThen() function (i.e. the parameters are both evaluated) or a statement (i.e. only one expression out of two is evaluated)?

MarkMLl

Is a function in rtl

https://gitlab.com/freepascal.org/fpc/source/-/commit/1e3f44965f9dca1afef94d89d50b6b7fbefc59ea
« Last Edit: May 06, 2022, 12:25:06 pm by tt »

PascalDragon

  • Hero Member
  • *****
  • Posts: 4137
  • Compiler Developer
Re: IfThen function
« Reply #52 on: May 06, 2022, 03:41:46 pm »
I added - and it was accepted - a patch for a generic ifthen() years ago. It is for sure in 3.2.0 but it may be even 3.0.4.
Michael merged it.

3.2.0 at the earliest, because generic functions are only supported from there on.

I added - and it was accepted - a patch for a generic ifthen() years ago. It is for sure in 3.2.0 but it may be even 3.0.4.
Michael merged it.

But is that an IfThen() function (i.e. the parameters are both evaluated) or a statement (i.e. only one expression out of two is evaluated)?

It's a function, otherwise there wouldn't be any parenthesis (and if it would be an intrinsic then Thaddy would have said it as such). Also we already have an if-statement. What we don't have is an if-expression.

BobDog

  • Sr. Member
  • ****
  • Posts: 266
Re: IfThen function
« Reply #53 on: May 18, 2022, 10:20:30 pm »

This seems to work OK, although it still evaluates both bits.
Code: Pascal  [Select][+][-]
  1. uses
  2. math;
  3.  
  4. var
  5.  d:double =0;
  6.  n:double =100;
  7.  
  8.  begin
  9.  SetExceptionMask([exZeroDivide,exInvalidOp]);
  10.  writeln(ifthen(d>0,n/d,13));
  11.  writeln('Press return to end');
  12.  readln;
  13.  end.
  14.  

 

TinyPortal © 2005-2018