A TADS3/adv3 module providing several basic data types/data structures

Some internal shuffling, mostly related to moving most of the integer math methods from Vector to Collection. This motivated by the fact that TADS3 really wants arrays declared in source to be List instances and not Vectors. That is, it is easy to do something like:

myObject: object
        someProperty = static [ 1, 2, 3, 4 ]
;

…but there’s nothing similar for Vector that doesn’t have downsides (someProperty = perInstance(new Vector([ 1, 2, 3, 4])) doubles the storage size, for example).

Collection

Anyway, the following math functions are on Collection instead of directly on Vector:

  • add(lst)
  • subtract(lst)
  • multiply(n)
  • divide(n)
  • dot(lst)
  • norm()
  • equals(lst)
  • relu()

…where lst in all cases is a Collection and n is an integer. All these methods are only safe to call on Collection instances whose elements are all integers.

There used to be a “normal” method (e.g. add()) that implemented type and bounds checking and an “unsafe” method (e.g. unsafeAdd()) that didn’t, but that’s been deprecated and now all methods are “unsafe” by default. My thinking here is that TADS3 doesn’t natively do safe bounds checking on arrays or type checking on operators (iterating out of bounds on a List or trying to add an integer to an object will both throw exceptions). And in practice I was always hoisting safety checks out of loops and then calling the unsafe methods in loops. So I wasn’t using the “normal” version of the methods much anyway.

Vector

There are now mutate-in-place versions of the basic math functions on Vector:

  • iadd(lst)
  • isubtract(lst)
  • imultiply(n)
  • idivide(n)

So if v = new Vector([ 1, 2, 3 ]) and you do v.imultiply(2), then v will contain [ 2, 4, 6 ].

The return value of each is self.

Matrix2D

Finally, Matrix2D has been refactored the same way as Colleciton/Vector: “unsafe” methods removed, default method removes the expensive type checks, and internal calls to “unsafe” methods updated to use the “normal” methods.