Recent

Author Topic: Conditional ternary operators For FreePascal?  (Read 5339 times)

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12893
  • FPC developer.
Any really useful new syntax in Delphi?  Seems it is all shorthand and copycatting nowadays.

But they are highly requested by many people long time ago, at least by Delphi users. Maybe FreePascal targets different sets of developers.

It is not the developers of Delphi that decide the features, but marketing.

Quote
You could say they are all short handed, but many modern languages, even C++ is adding more syntax sugar to the language.

I can't speak for C++, but in Delphi's case it is obviously riskless superficial features to keep the subscription train going.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 12893
  • FPC developer.
So this is not just syntactic sugar, it allows you to use complex expressions on constants that was not possible before.

And you think THAT is the reason it was added ?  :)

nanobit

  • Full Member
  • ***
  • Posts: 189
Look at the C standard, C itself takes a lot of new features from other languages. For example since 2023 C now supports enum types without an underlying ordinal type, something that first was introduced in Pascal.
Wrong. C enum has an underlying ordinal type: default type or declared type (newer feature).

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 12387
  • Debugger - SynEdit - and more
    • wiki
Re: Conditional ternary operators For FreePascal?
« Reply #18 on: August 08, 2025, 09:33:43 am »
This thread is moderated. Please see the note on top (in the first message of this thread)

gues1

  • Guest
Well this is not just syntactic sugar, it allows you to do the following:
Code: Pascal  [Select][+][-]
  1. const a = if cond then val1 else val2;
A constant can only be assigned exactly once, so the following is not possible:
Code: Pascal  [Select][+][-]
  1. const a;
  2. if cond then a:=val1 else a:=val2;
So this is not just syntactic sugar, it allows you to use complex expressions on constants that was not possible before.

The idea that a constant can be dynamically assigned a value is, well, a fallacy. By definition, a constant is constant. It does not change based on context or conditions. Therefore, that concession on the current proprietors of Delphi is most likely chasing the .NET shadow or whatever language occupies the latest fad.

Who said that in Delphi you can write a thing like that (I mean const c := if ....) ?

From what I know, this certainly isn't possible in the normal variable declaration sections (interface, implementation, and as local variable). The const declaration must be known at compiler time, not at runtime, and the "if" statement already contradicts this.

If we then talk about the concept of inline variables (which isn't part of FPC), then perhaps this will be possible because it can be resolved at runtime.
But will see when Delphi 13 Florence wil be out.

NEWS note: this is known in the public e-mail lists from authorized channel so no issue to talk about, but not published in the Embarcadero blog yet, there will be a free Webinar on 10 September about the new features and the realease of new Rad Studio.

PascalDragon

  • Hero Member
  • *****
  • Posts: 6396
  • Compiler Developer
If there is something in Delphi, then it should be brought to FreePascal as early as possible

No. There can be features where we feel that the spirit of Pascal is violated too much (inline variables) or the implementations are simply not trivial (implements on a field of a class type, dynamic packages, delayed imports).

 

TinyPortal © 2005-2018