DWScript multifarious tidbits

Find beneath this paragraph a spring mishmash of recent happenings from the DWScript repository!
Overview Dialog, Lambdas and Templates.


The long planned support for templates has begun!

As it represents a significant workload (especially to ensure a good test coverage), it is being introduced piecemeal, type by type, expression by expression, with unit tests added along the way.

The syntax is similar to Delphi, and ultimately, the goal is to handle all the cases Delphi can… but it is really a template approach rather than a generic one. This means that while the templates are parsed, and while constraints are supported, the final strong typechecks occur when specializing a template rather than when compiling the template.

The aim here is to be able to support operators, so that you can write code like

function TWhatever<T>.Sum(a, b : T) : T;
   Result := a + b;

which will work for any type T that suports a ‘+’ operator, and similarly for all the comparison operators, helpers, and other basic functionality. All this with neither complex low-level machinery nor interface-based overhead.

If a type does not support ‘+’ then you will get that error when trying to write ‘TWhatever<Boolean>’ for instance.

The other immediate usage case for templates is in SmartPascal, to facilitate the declaration of strongly-typed external classes (for instance for Promises).

Currently, the template support does not extend much beyond what’s in the unit tests, for everything else, you will get errors like “TdwsWhateverInternalClass does not support specialization yet”.

Overview Dialog

The SourceUtils\dwsOverviewDlg unit implements a simple overview dialog for a code editor.

It is a tree view that lists all declared types and methods in a source files, and can be used to jump in a code editor across declaration, methods and implementations.

Partial Lambda support in Scripts

Lambdas (and anonymous methods) that are not closures are now allowed in scripts, formerly they were only accepted for the JavaScript codegen (SmartPascal).

Not being a closure means they cannot capture anything from their context. While this is very restrictive, this still opens a variety of uses, like for array sort and map functions, where you sometimes do not need any context, and where using a lambda can lead to clearer code than declaring a function and then referring it.


The JavaScript codegen received a few minor improvements.

Imrpoved test coverage and some error reporting.

6 thoughts on “DWScript multifarious tidbits

  1. It seems like DWScript has far surpassed Delphi itself in terms of language features! Some Qt bindings and an Eclipse or IntelliJ plug-in, and you’d have a next-generation Delphi.

  2. Hi, Mr Eric,

    Since now Delphi is able to compile app to iOS, would you please create an app like Pythonista for iOS for Pascal? I’ve been wanting a modern Pascal IDE for mobile (especially iOS) since I saw iPad for the first time. I think only DWS that is able to do that because it uses scripting instead of compiling, and also sand-boxing. And the demo of live IDE is a proof that it should be possible to use DWS to create Pascal IDE for iOS as advance as Pythonista. Once such an app is available, I’ll buy it in a heart beat! If it’s not enough, I’ll help on the testing too.

    Please, please… make a Pascal IDE for iOS, Mr Eric. 😊

    Thank you.

    Best regards,


    Pythonista: http://omz-software.com/pythonista/

  3. Oh, one more thing, Mr Eric… I’m a FreePascal programmer, especially on Linux. Since FPC v.3 has already supported many new Delphi features, do you have a plan for DWS to support Linux too? At least as a static library (compiled from Delphi) that can be called from another FPC-generated executable. That would provide us —Pascal programmers— a PHP-like tool for web programming.

  4. @Bee alas I do not have access to a Delphi of version that compiles for iOS, nor do I have a Mac to create the final binary, and my iPad is an old one, hehe, but others are free to try!

    Progress on FreePascal is rather slow, stumbling blocks are some generics incompatibilities (some have been replaced or rewritten, more remain), but mostly revolve around UnicodeString support in the FPC/Lazarus RTL.

  5. @Eric: Alright then.

    Why is it so hard to have a good Pascal IDE for iOS while there are so many available for other languages? There is Pythonista for Python, Codea for Lua, Kodiak for PHP, Procoding for JS, techBasic for Basic, Lisping for Lisp, Raskell for Haskell, Dringend for Obj-C, Continous for C# and F#, Swift Playground for Swift, Coda for HTML, and many many more… but none for Pascal. Zero, nada. It’s so sad. No wonder why Pascal is like an alien to young people… because it’s either too expensive (Delphi), too complicated (FPC/Lazarus), or not available in their platform of choice (iOS). 😟

  6. Well, if I can get it to compile under FreePascal, my next targets will be Linux and Android. Also that would be for basic stuff, building an IDE is a whole different project on its own, and for new users, there is another whole project in getting online documentation into shape…

Comments are closed.