Here is the news summary for September 2012, top new items are initial FreePascal support and introduction of lambdas syntax.
Minor language improvements
- Hexadecimal literals prefixed with ‘0X’ (zero x/X) are now supported.
- Binary literals prefixed with ‘0B’ (zero b/B) are now supported.
- Added ClassParent to TObject.
- Methods can now be marked as “empty“, the compiler then assumes an empty implementation body (same as in Oxygene).
Latest SVN now compiles under FreePascal 2.7.1, and a fair amount of the unit tests now pass in Windows.
Impacts on Delphi usage:
- generic collections in (dwsUtils) were adapted, and may require changes in your code if you were using them, the updated collections are a bit “less” generic, but should run faster.
- enumerators that were using anonymous methods (“reference to”) have been changed to standard object methods (“procedure of object”), you’ll have to adjust your code if you were using them. On the upside, they’ll should be slightly faster now.
- code no longer compiles in XE3, whose compiler now gives cryptic internal errors. Code still compiles fine under XE and XE2, so my advice is to wait for XE3 update 1.
Limitations in FreePascal:
- Delphi and DWScript assume UTF-16 strings, while FreePascal uses UTF-8, with UnicodeString support in FPC being still limited, the code currently relies on UTF-8 in FreePascal + conversions, this means String are currently slow in the script engine, and can be quite glitchy for non-BMP Unicode characters.
- The asm helpers haven’t been ported to FreePascal yet, so overall performance in the script engine, even outside of strings, is quite lower in FreePascal (about twice slower AFAICT).
- The code has been tested only with a Win32 target, it likely doesn’t compile or runs for other targets yet.
Hopefully the above limitations will get resolved or worked around in future versions.
RTTI first steps
Initial support for RTTI has been introduced, currently it’s limited to properties and class attributes, and only the low-level storage and interfaces have been defined. If you’re interested, see the unit tests for sample code.
It allows enumerating attributes, getting property types, as well as invoking property getters & setters for simple types.
- Introduced Lambda syntax, the lambda expression syntax is similar to C#’s syntax with “lambda” keyword in front to make it less of an operator soup
DoSomething( lambda (param1, param2) => param1+param2 );
lambda statements are supported too, when ‘=>’ is not present
DoSomething( lambda (param1, param2) DoSomethingElse(param1); Result := ComputeSomething(param2); end );
Lambdas are currently capable of compile-time type-inference, ie. they are strongly-typed and can be used as less verbose alternatives to the “anonymous methods” syntax.
- Fixed a bug when Exit() is used in a constructor
And yes, current lambda syntax differs from Oxygene (which uses just ‘->’ with no prefix), we felt the “=>” operator was more readable and more “standard”, the presence of a “lambda” prefix makes them more prominent, and less prone to operator-soup.
There are other advantages, such as parameter-less lambdas (which are not necessarily constants, since they are effectively closures), and the presence of a keyword, which means support for alternative lambda syntax can be added at future times without affecting backward compatibility. I’ll try to discuss these in a future article.