Dynamic arrays as stacks, tighter JavaScript

Here is a summary of the changes of recent happenings in the SVN.
Note that this list doesn’t include the very latest changes and features, which will get an article of their own.


  • dynamic arrays now support Pop(), Peek() and Push() and can be used as stacks.
  • dynamic arrays Add() and Push() now accept a variable number of parameters, and in addition to elements, they now accept dynamic arrays too (which will be concatenated)
  • Count() can now be used as an alternative to Length() for static and dynamic arrays.
  • Class variables are now supported, both by classes and records.
  • Oxygene-like syntax for explicitly scoped “enum”  and “flags” is now supported:
    MyEnum = enum (One, Two, Three)
    MyFlags = flags (Alpha, Beta, Gamma)

    Both forms must be prefixed, as in MyEnum.Two, the “enum” form is otherwise similar to classic enumerations. The flags form is a special case in which the elements values are powers of two (f.i. MyFlags.Beta = 2, MyFlags.Gamma = 4)

  • class methods can now be marked as static.
  • Class const syntax is now supported (had to be written as just ‘const’ before)
  • multi-line indented strings can now be either #” or #’
  • tweaked overload metric to give precedence to Float over Integer when Variants are involved
  • added a new hint if you redeclare a variable with the same name in a local sub-scope (doesn’t apply across sub-procedures)
  • improved some error locations, other minor fixes

Built-in functions and interfacing

  • Partial RTTI support for indexed properties (Stefan Glienke)
  • StrSplit() splits a string on a delimiter and returns an array of string
    StrSplit(‘jan,feb,mar’, ‘,’) returns [‘jan’, ‘feb’, ‘mar’] as a dynamic array
  • StrJoin() takes an array of string and returns a string made by joining all the individual strings
    StrJoin(a, ‘,’) with a the above array would return ‘jan,feb,mar’

JavaScript CodeGen

  • various improvements to the output when optimizing for size (about 10% of size reduction)
  • fixed an issue with var parameters of a parent procedure used in a local procedure or anonymous method
  • smart-linker is now capable of eliminating some cases of unused interfaces
  • fixed an issue with aliased types used as record fields

Support Tools

  • added fledgling code metrics classes

As a side note, the recent (and planned) improvements to dynamic arrays are currently tipping the generics vs templates balance towards templates, as they’re becoming capable enough “generic collections” on their own, meaning that “classic” generics wouldn’t bring much extra capability to the language for everyday usage.

4 thoughts on “Dynamic arrays as stacks, tighter JavaScript

  1. Excellent! I’d like to state here in public that I love what you are doing to the Object Pascal. I can only hope some of your improvements will find a way into Delphi …

  2. I like it too. In fact, I was just wondering if any of the source code would be useful to Delphi developers as a general resource.

  3. I’m not sure about using dynamic arrays as generic collections and thus eliminating the need for classic generics.

    Your implementation of dynamic arrays right now can fulfill the function of two basic collections: List and Stack. But they don’t do so well for Queue, Map (Dictionary,) Multimap or Heap collections, for example…

  4. @Mason Wheeler
    No, they don’t fulfill that need, but I’m feeling that adding generics only for those might not be worth the effort.

    (and FWIW, arrays as maps will probably come, the array syntax just lends itself to it in the form of associative array, f.i. “array [String] of TObject” for a String/TObject dictionary, or “array [Integer] of Float” for a sparse array of floats)

    Templates would allow supporting those extra collections, in a richer manner. And just about anything that Generics can do, Templates can do too (with the same syntax), while templates allow things generics can’t do.

    For instance the following would be a valid template for any type that has a “+” operator (native or overloaded):
    function Adder(a, b : T) : T;
    Result := a + b;

    Achieving the same thing with generics would be quite convoluted/inefficient, involving constraints, interfaces, boxing classes, etc. Just have a look at the comparer code in Delphi’s Generics.Collections or the C#/.Net stuff… simple features sometimes requires huge machinery with generics.

    On the other hand, C++’s STL show how powerful templates can be — as well as how messy they can become too 😉 — but once you step outside collections, I find the STL less messy than Generics are.

Comments are closed.