Functional style - examples

Rust vs current C++

Proposed C++

(and ditto for Delphi …)

Javascript … continuations (completion handlers ?)

These are asynchronous functions (like TTask, but returning a value) … that can be composed into further work to be performed, using that thread, without paying the cost of winding up a thread only to launch a new one to do the next step of the process.

These are Promises - the fetch() call returns a promise.

Promises have been around in Javascript for a long time, initially as a library but were added to the official Javascript around 2014.

I tried to implement something like this in Delphi, but the lack of Lambdas (arrow functions in JS) just made everything too verbose. The closest I got to this is my VSoft.Awaitable library (which is a wrapper over OmniThreadLibrary).

1 Like

I considered mentioning promises/futures … as opposed to our TFuture … but I wanted to keep it bite-sized, and am also no expert on javascript.

I have been accumulating material over the year that could be a talk called “Vocabulary” …

I have an idea that javascript has developed along a timeline with callbacks … then promises and futures … and then async/await.

I’ve seen that C# has co-routines, tasks, and async/await/yield. And completion handlers, I think?

And C++ has promises/futures and has been adding co-routines just now, which in typical C++ fashion at the moment looks like a mechanic upturned a shipping crate of tools onto a garage floor.

Some of it has been slowly congealing into a more uniform perspective, that I’m also trying to picture in Delphi terms, but I’m not there yet.

PS : I have only just recently realised we have the AIO library in Delphi that apparently implements greenlets (co-routines)

PPS : … and that there was a ‘Coroutine Pascal’ in the past.
PPPS : and ‘Garden Point Component Pascal’ Component Pascal

PPPS : I’d be very happy to hear much more about this stuff from anyone that felt like talking about it … it’s surely something Delphi can develop towards better in the future.

:rofl: :rofl: :rofl:

Do you know how many complex language features embarcadero have implemented in the last 10 years? The last ones were in 10.3 Rio.

I have advocated for language enhancements for many years - but always gets pushed to the back of the queue while they try to keep up with the constantly changing mobile dev tool chains. The reality is embarcadero simply do not have the resources to do this.

My original post was almost 6 years ago - you would think that a lot could be achieved in 6 years, but that isn’t what happened.

1 Like

Sure, I understand that.

The changes in C++20 and C++23 are pretty huge.
Gcc and Clang are seen as the major worldwide compilers, with Microsoft seen as a bit less in general.
Except Microsoft have already included all? many? of the newest features in their compiler.

C++Builder implements C++17. Dinkumware provided the standard template library … but has wound down its business now, I think. So they (Embarcadero) have a real issue there too.

I’m assuming things may come to a head at some stage … open-sourcing the Delphi and CB compilers ??
Or some step in that direction??
Surely it can’t just coast down to a stand-still …

Not sure if I’m going too low level for you… but I believe co-routines could be implemented with Fibers for some use cases anyway.

From @Glen_Kleidon2 Melbourne talk this month, he was talking about a missing WriteAsync function in delphi. The actual IO could be handled by a IO Completion Port or using Overlapped IO. Once the Write call has been scheduled… the WriteAsync call would switch to/or create another fibre that is waiting on the IO port… which would then use SwitchToFiber to load back to code to continue the function that called WriteAsync. Sleep calls could be handled in a similar fashion - Using CreateWaitableTimer.

1 Like

I’m convinced that a lot can be done in six years. But it requires resources. If there are none, nothing will get done.

I wish they fixed the basics first, i.e.: TClientDataset is as broken now as it has always been.


RemObjects on LINQ.


Each LINQ expression maps to an (extension) method on the Sequence type, under the hood.
Implementations for these methods are provided by the framework, on .NET, and by the Elements libraries (libToffee, Cooper.jar and Island RTL) on the other platforms.

  • distinct
    – maps to .Distinct()
  • group X by Y / group by Y select x
    – maps to .GroupBy()
  • from X in Y (inner from)
    – maps to .SelectMany() with optional Cast<T> if the type is specified;
    the result is turned into a special anonymous class where both original and new are available.
  • join on X equals Y
    – maps to .Join()
  • order by X
    – maps to .OrderBy, secondary order to .ThenBy()
  • order by X descending
    – maps to .OrderByDescending, secondary order to .ThenByDescending()
  • reverse
    – maps to .Reverse()
  • where X
    – maps to .Where()
  • select X
    – maps to .Select()
  • skip X
    – maps to .Skip()
  • skip while X
    – maps to .SkipWhile()
  • take X
    – maps to .Take()
  • take while X
    – maps to .TakeWhile()
  • with (Oxygene) and let (C#)
    – maps to .Select() with a special anonymous that makes both the original and the new variable available.

  1. Wow. I remember reading this years ago … and now I can realise how little of it I really took in.