Recent

Author Topic: IfThen function  (Read 6765 times)

Чебурашка

  • Hero Member
  • *****
  • Posts: 569
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: IfThen function
« Reply #30 on: April 29, 2022, 08:53:31 am »
or macros like the one I wrote above.

As I've already pointed out, FPC's macros don't take parameters. Your example in #6 won't work.

MarkMLl

Of course, I was referring to C marcos.
« Last Edit: April 29, 2022, 09:07:07 am by tt »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Paolo

  • Hero Member
  • *****
  • Posts: 510
Re: IfThen function
« Reply #31 on: April 29, 2022, 09:29:29 am »
Uhm.... I did not catch this ifthen implication.
If then esle construct is to select the right branch under boolean condition skipping the other branch, what is the purpose of ifthen if both branches are computed ?

Чебурашка

  • Hero Member
  • *****
  • Posts: 569
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: IfThen function
« Reply #32 on: April 29, 2022, 09:36:10 am »
Uhm.... I did not catch this ifthen implication.
If then esle construct is to select the right branch under boolean condition skipping the other branch, what is the purpose of ifthen if both branches are computed ?

Also free pascal IfThen() function is often very useful, for example:

Code: Pascal  [Select][+][-]
  1. Color := IfThen(condition, clGreen, clRed);
  2.  

Of course if one wants to skip evaluation of unused branch, IfThen is not the solution and if then else must be used unless new constructs are added.
« Last Edit: April 29, 2022, 09:38:40 am by tt »
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: IfThen function
« Reply #33 on: April 29, 2022, 01:57:42 pm »
PascalDragon once gave me some hope that the if-then-else (be it a function intrinsic or some kind of a ternary operator, whatever) construct will get into language eventually...

Чебурашка

  • Hero Member
  • *****
  • Posts: 569
  • СЛАВА УКРАЇНІ! / Slava Ukraïni!
Re: IfThen function
« Reply #34 on: April 29, 2022, 02:43:41 pm »
PascalDragon once gave me some hope that the if-then-else (be it a function intrinsic or some kind of a ternary operator, whatever) construct will get into language eventually...

In PascalDragon we trust.
FPC 3.2.0/Lazarus 2.0.10+dfsg-4+b2 on Debian 11.5
FPC 3.2.2/Lazarus 2.2.0 on Windows 10 Pro 21H2

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: IfThen function
« Reply #35 on: April 29, 2022, 03:35:08 pm »
PascalDragon once gave me some hope that the if-then-else (be it a function intrinsic or some kind of a ternary operator, whatever) construct will get into language eventually...

In PascalDragon we trust.

I did take the trouble to link to his posting and the unapplied patches in my first response.

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

Zoran

  • Hero Member
  • *****
  • Posts: 1830
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: IfThen function
« Reply #36 on: May 01, 2022, 01:55:31 pm »
PascalDragon once gave me some hope that the if-then-else (be it a function intrinsic or some kind of a ternary operator, whatever) construct will get into language eventually...

In PascalDragon we trust.

I did take the trouble to link to his posting and the unapplied patches in my first response.

MarkMLl


I know, Mark, I didn't miss your post.
I just wanted to say that, although his work didn't make it in the language at the time, we might get this feature after all (in some different form perhaps).

PascalDragon

  • Hero Member
  • *****
  • Posts: 5481
  • Compiler Developer
Re: IfThen function
« Reply #37 on: May 02, 2022, 02:06:32 pm »
Apropos Concat(), I admit to almost always using its equivalent + operator. However as Pascal gains more overloading and dynamic array capabilities I'd be far happier if something like a _ operator were defined to (also) mean concatenation, so that it was possible to override + meaning "add these arrays" and _ meaning "concatenate these arrays". But I know that's not going to happen.

_ is already used in main as digit separator. Best not to confuse that as an operator as well...

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: IfThen function
« Reply #38 on: May 02, 2022, 02:25:58 pm »
_ is already used in main as digit separator. Best not to confuse that as an operator as well...

Plus it's valid in an identifier. The only realistic way something like that would work- in just about any language- would be if there were mandatory whitespace on both sides. And that ain't going to happen.

Hmm. How about ^ in a string or array context as concatenation, even if it's not overridable?

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: 5481
  • Compiler Developer
Re: IfThen function
« Reply #39 on: May 02, 2022, 03:13:40 pm »
Hmm. How about ^ in a string or array context as concatenation, even if it's not overridable?

So you never dereference a PString or a pointer to a static array? ;)

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: IfThen function
« Reply #40 on: May 02, 2022, 04:01:54 pm »
So you never dereference a PString or a pointer to a static array? ;)

Please correct me if I'm wrong, but I didn't think there was a mode in which a Pstring or ordinary pointer was automatically dereferenced. So postfix ^ (applied to a pointer) and infix ^ (applied to two strings) are distinct.

And I know from discussion with Jonas years ago that ^ is unlikely to be added to the list of operators which can be overridden.

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: 5481
  • Compiler Developer
Re: IfThen function
« Reply #41 on: May 03, 2022, 09:57:26 am »
So you never dereference a PString or a pointer to a static array? ;)

Please correct me if I'm wrong, but I didn't think there was a mode in which a Pstring or ordinary pointer was automatically dereferenced. So postfix ^ (applied to a pointer) and infix ^ (applied to two strings) are distinct.

I'm not talking about automatic dereferentiation: Does SomePString^^SomeString really read so much better than SomePString^+SomeString (and yes, I left any spaces out on purpose)?

And I know from discussion with Jonas years ago that ^ is unlikely to be added to the list of operators which can be overridden.

That doesn't make the ^ a better choice for something like this.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: IfThen function
« Reply #42 on: May 03, 2022, 10:22:02 am »
I'm not talking about automatic dereferentiation: Does SomePString^^SomeString really read so much better than SomePString^+SomeString (and yes, I left any spaces out on purpose)?

But the issue is not replacing + as concatenation, it's decoupling + from concatenation so that it could potentially be used for summing (the content of) dynamic arrays.

Quote
That doesn't make the ^ a better choice for something like this.

What's the alternative? Just about everything else is either already used in the syntax, or will be swallowed by the lexer, or will introduce internationalisation issues because it's not in 7-bit ASCII.

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.

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

dseligo

  • Hero Member
  • *****
  • Posts: 1221
Re: IfThen function
« Reply #43 on: May 03, 2022, 11:14:57 am »
What's the alternative? Just about everything else is either already used in the syntax, or will be swallowed by the lexer, or will introduce internationalisation issues because it's not in 7-bit ASCII.

! ? | \ ~ "

And some character pair could probably also be made.

MarkMLl

  • Hero Member
  • *****
  • Posts: 6686
Re: IfThen function
« Reply #44 on: May 03, 2022, 11:22:06 am »
What's the alternative? Just about everything else is either already used in the syntax, or will be swallowed by the lexer, or will introduce internationalisation issues because it's not in 7-bit ASCII.

! ? | \ ~ "

And some character pair could probably also be made.

I was wondering about ~ but was wary since some "regional ASCIIs" might omit it. If safe, it would be the obvious contender since I don't think the C family uses it as an infix operator so nobody could argue that it would break expected idioms.

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

 

TinyPortal © 2005-2018