[fpc-pascal] Case statement for class introspection

Michael Van Canneyt michael at freepascal.org
Sat Jan 15 02:30:30 CET 2022



On Sat, 15 Jan 2022, Ryan Joseph via fpc-pascal wrote:

> I saw a new syntax in Swift which I thought was clever and fits a pattern
> I've seen before.  Basically it's a case statement for class types which
> lets you branch depending on which class type the class instance is at run
> time.

I think Scala did it before Swift.

>
> I wonder if this could be implemented in FPC? The syntax would be kind of clumsy though since you can't declare  scoped variables in Pascal so you would need to do lots of casts but it's still cleaner than the equivalent code as if statements.

This idea has been proposed before by Izak Maciej. 
I'm all for it.

Michael.


More information about the fpc-pascal mailing list