gm2
[Top][All Lists]
Advanced

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

Re: MathLib0.real() not supported


From: Benjamin Kowarsch
Subject: Re: MathLib0.real() not supported
Date: Sat, 29 Oct 2022 17:58:09 +0900

On Fri, 28 Oct 2022 at 00:39, Doug Kearns <dougkearns@gmail.com> wrote:

It appears that PROCEDURE real(x: INTEGER): REAL; was removed from
MathLib0 in PIM4.

There is no need for any such library function because it is already built-in.

Under section 10.2 "Standard procedures" on page 150 of PIM, 4th Edition, you will find:

FLOAT(x)     x of type INTEGER represented as a value of type REAL.

In fact, it was already present under the same section on page 162 of PIM, 3rd Edition.

In other words, the function in MathLib0 was entirely redundant to begin with.

Even so, the built-in functions CHR() and FLOAT() are redundant because of built-in function VAL(). They merely exist for convenience, because Wirth felt that typing VAL(CHAR, x) and VAL(REAL, x) was inconvenient and needed a shorter alternative, arguably this was an admission of bad design. If you think your design is inconvenient and needs a more convenient alternative, perhaps you should come up with a better design, such as a type conversion operator as it existed in VAX Pascal and as it exists in our Modula-2 revision:

char := int :: CHAR;
real := int :: REAL;

which also works with all other built-in types and combinations.

The TRUNC() function is also problematic because it performs both truncation and type conversion. A function should either be a mathematical function or a type conversion function but not both. The type conversion part is already taken care of by function VAL(). And as a truncation function it could as well have been put into MathLib0 as trunc(). Thus, TRUNC() is also redundant and unnecessary.


This procedure gets a bit of a run in King's "Modula 2 - A Complete
Guide" and, according to the manual I have, was supported in Logitech
Modula-2/86 version 2.

A global find and replace, substituting FLOAT() will solve that very easily.

Alternatively, write yourself a library with

PROCEDURE real( x : INTEGER ) : REAL;
BEGIN
  RETURN FLOAT(x)
END real;

but you will then need to import that library before using it.

hth, rgds
benjamin

reply via email to

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