Leaps and bounds of DWScript

A DWS 2.2 preview zip (199 kB) has been posted, it is an SVN snapshot, and features recent additions to DWS:

  • Contracts are now partially supported: ensure, require and old are available and use the same syntax as Prism contracts, inheritance is supported, class invariants are not in just yet, mostly for syntax indecision reasons, see this thread.
  • the implies operator is now supported, “a implies b” is equivalent to “(not a) or b”, or in other words, it is false only if a is true and b is false.
  • Assert() is supported, and will trigger EAssertionFailed in case of, well, an assertion failure. A compiler option has been added to control the generation of assertions.
  • Exception now has a StackTrace method, which will return a textual stacktrace script-side. Runtime errors now also include a stack trace, and new Delphi-side methods provide access to even more details.
  • the in operator has been extended to allow class overloading, f.i. you can now use “if (aString in someStringList) then…”, the not in form is also supported.

A fair chunk of the error and exception code has been refactored, if you were relying on it, all the preexisting functionality is still there, though it has been shuffled around to (hopefully) more relevant locations.

6 thoughts on “Leaps and bounds of DWScript

  1. Hello Eric!

    I already commented some time ago regarding Free Pascal support.

    There was quite a bit of development in FPC in the last months and Delphi compatible generics and extended records are mostly supported now in the development version.

    I have managed to compile dwsXPlatform (heavy adjustments), dwsStrings (unchanged) and dwsUtils (some adjustments) and currently I’m trying to get dwsErrors to compile. But that’s currently not possible as constructors are not yet supported inside extended records.

    I’ll report back once that has become possible. 🙂


  2. I posted a suggested syntax for “class invariants” (a horrible name since they represent a set of conditions that must pertain, not a set of values that do not change… but I digress)…

    Having just looked at the syntax for these in Prism, I am struck by the way my suggestion actually makes more sense in conjunction with method “contracts”, employing the “ensure” keyword in a way that echoes that of methods (helping make the connection that class invariants are evaluated after any method contracts).

    i.e. methods may have an “ensure” clause, and any “ensure” clauses in the “invariants” section that I suggest would then follow.

    The only thing missing from my suggestion is a scope directive, which you may or may not be intending to adopt. If so, this could be easily incorporated:


    ensure TMyClass
    fField > 0;

  3. @Jolyon Smith
    It’s interesting, though I guess there should be some way to relate the class to its invariants (by looking at the class definition, you don’t known directly if it has invariants or not, and when implementing the class, you’ll need to know about thos invariants you must respect)

  4. @Eric:
    Yes, you can pick the nightlies here: ftp://ftp.hu.freepascal.org/pub/lazarus/snapshots/
    You need the Lazarus snapshots that contain FPC 2.5.1 (either Win32 or Win64 depending on your OS/preference ^^)

    But be careful. This is from Lazarus trunk and you might experience nasty surprises regarding the IDE. 😛 Also the new generic syntax for the modes Delphi and ObjFPC as well as the extended record syntax are not yet supported.


  5. Small addition to last comment:
    “(…) are not yet supported by the IDE and its tools.”


Comments are closed.