gm2
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Modula-2 generics, exceptions, and optional parameters - how widely supp


From: Alice Osako
Subject: Modula-2 generics, exceptions, and optional parameters - how widely supported?
Date: Wed, 27 Mar 2024 16:52:18 -0400
User-agent: Mozilla Thunderbird

I know that ISO Modula-2 added both exceptions and optionally, generics. Further, I know that GNU Modula-2 also supports optional parameters and optional return values, but as far as I can tell those are unique to GM2. My question is, which compilers support the ISO generics, how well supported are the ISO exception handling, and what options would I have for support under non-ISO compilers, if any?

For context: I've run into an issue regarding the design of a unit testing framework for Modula-2: in order to provide support for several of the common test assertions, the assertion must be able to accept arguments from  a number of different types, and in some cases, accept procedural parameters which themselves accept arguments of those types. For example, some of the typical test assertions would be:

* assertEqual(pred: ComparisonPredicate; a, b: <compared type>)
* assertNotEqual(pred: ComparisonPredicate; a, b: <compared type>)
* assertGreaterThan(pred: ComparisonPredicate; a, b: <compared type>)
* assertGreaterThanOrEqual(pred: ComparisonPredicate; a, b: <compared type>)
* assertLessThan(pred: ComparisonPredicate; a, b: <compared type>)
* assertLessThanOrEqual(pred: ComparisonPredicate; a, b: <compared type>)
* assertIs(a, b: <compared pointer type>)
* assertIsNot(a, b: <compared pointer type>)
* assertIn(member: <enum type>; set: <set type>)
* assertNotIn(member: <enum type>; set: <set type>)

... where ComparisonPredicate is something like:

TYPE ComparisonPredicate: PROCEDURE(<compared type>, <compared type>): BOOLEAN;

Now, it would be possible to simply use assertTrue() and assertFalse() assertions with the appropriate comparison predicates, there would be a loss of specificity in the test output (i.e., it would not say what sort of failure it was automatically as most test frameworks do).

Most frameworks also support testing for exceptions, with the assertRaises() (or assertThrows(), as appropriate for the language) being a typical assertion.

Most strongly-typed languages for which there are existing xUnit type frameworks have had both exceptions and generics from, if not the outset, then at least fairly early on, while several of the other languages with such testing frameworks are not strongly typed (Python, Smalltalk, etc.). The main exception to this is C, but C has the preprocessor macros which can perform much the same duties.

So my question is, what are my options with Modula-2? I know that M2PP is one possibility, but I would prefer to stay within the core language if possible. However, I am guessing that M2PP is my best option for working with compilers that only support PIM.

Any advice?



reply via email to

[Prev in Thread] Current Thread [Next in Thread]