Discussion:
Maximum value of basic types
(too old to reply)
akarl
2005-07-25 01:27:52 UTC
Permalink
Hi all,

My interpretation of section 10.3 (Predeclared Procedures) of the
Oberon-2 report (March '95) is that MAX and MIN are defined for any
basic type, which of course is wrong since MAX(BOOLEAN) and MIN(BOOLEAN)
doesn't make sense. I think

Name Argument type ...

MAX(T) T = basic type ...
T = SET ...
MIN(T) T = basic type ...
T = SET ...

should be changed to

Name Argument type ...

MAX(T) T = numeric type or CHAR ...
T = SET ...
MIN(T) T = numeric type or CHAR ...
T = SET ...

Comments?


Regards,
August
Stefan Salewski
2005-07-25 14:58:49 UTC
Permalink
Post by akarl
Hi all,
My interpretation of section 10.3 (Predeclared Procedures) of
the Oberon-2 report (March '95) is that MAX and MIN are defined
for any basic type, which of course is wrong since MAX(BOOLEAN)
and MIN(BOOLEAN) doesn't make sense. I
I think type BOOLEAN is an ordered type,
so (FALSE<TRUE) is an correct expression --
I think with value TRUE.

So MIN(BOOLEAN) is FALSE and MAX(BOOLEAN) is TRUE
or vice versa.

Best regards

Stefan Salewski
akarl
2005-07-25 15:36:25 UTC
Permalink
Post by Stefan Salewski
I think type BOOLEAN is an ordered type,
so (FALSE<TRUE) is an correct expression --
I think with value TRUE.
So MIN(BOOLEAN) is FALSE and MAX(BOOLEAN) is TRUE
or vice versa.
If BOOLEAN was an ordered type then `<', `<=', `>' and `>=' would accept
BOOLEAN operands (but they don't).

August
Greg Haynes
2005-07-26 03:15:05 UTC
Permalink
Post by akarl
Post by Stefan Salewski
I think type BOOLEAN is an ordered type,
so (FALSE<TRUE) is an correct expression --
I think with value TRUE.
So MIN(BOOLEAN) is FALSE and MAX(BOOLEAN) is TRUE
or vice versa.
If BOOLEAN was an ordered type then `<', `<=', `>' and `>=' would accept
BOOLEAN operands (but they don't).
August
The type of MAX(BOOLEAN) (and MIN(BOOLEAN)) is BOOLEAN.
The only relational operators that apply to BOOLEANs
are "=" and "#" (Sec. 8.2.4). So I guess you would say that
BOOLEAN is not an "ordered" type. (I don't believe the term
"ordered type" is used in the Oberon-2 report).

-Greg
Stefan Salewski
2005-07-26 11:27:21 UTC
Permalink
Post by Stefan Salewski
I think type BOOLEAN is an ordered type,
so (FALSE<TRUE) is an correct expression --
I think with value TRUE.
So MIN(BOOLEAN) is FALSE and MAX(BOOLEAN) is TRUE
or vice versa.
This statement of me seems to be wrong --
maybe i confused it with PASCAL or MODULA, the
predecessors of OBERON.

In any case, expressions like MIN(BOOLEAN),
MAX(BOOLEAN) or (FALSE<TRUE) would be not very
usefull.
Chris Burrows
2005-07-26 05:05:54 UTC
Permalink
My interpretation of section 10.3 (Predeclared Procedures) of the Oberon-2
report (March '95) is that MAX and MIN are defined for any basic type,
which of course is wrong since MAX(BOOLEAN) and MIN(BOOLEAN) doesn't make
sense. I think
Perhaps - I see your point - but does it really matter to anybody other than
a compiler-implementor? The general spirit of Oberon is not to introduce
unnecessary complications by having exceptional rules to exclude special
cases that are otherwise harmless.

The results of MIN and MAX are implementation-dependant. All the compiler
implementor has to do when the parameter to either function is a BOOLEAN is

a) return a BOOLEAN value

b) ensure that MIN(BOOLEAN) # MAX(BOOLEAN)

c) document the behaviour in the implementation-dependent section of the
compiler documentation.

If the report is changed as you suggest, that would

a) add the further complexity of error-handling to the compiler

b) break all existing compilers that conform to this part of the report.

If the report is left as it is, does it cause any problems for the end-user
of the compiler? I think not.

--
Chris Burrows
CFB Software
http://www.cfbsoftware.com/gpcp
akarl
2005-07-26 13:19:24 UTC
Permalink
Post by Chris Burrows
My interpretation of section 10.3 (Predeclared Procedures) of the Oberon-2
report (March '95) is that MAX and MIN are defined for any basic type,
which of course is wrong since MAX(BOOLEAN) and MIN(BOOLEAN) doesn't make
sense. I think
Perhaps - I see your point - but does it really matter to anybody other than
a compiler-implementor? The general spirit of Oberon is not to introduce
unnecessary complications by having exceptional rules to exclude special
cases that are otherwise harmless.
To allow e.g. `MIN(BOOLEAN)' and disallow e.g. `FALSE < TRUE' is very
inconsistent. The OOC compiler do disallow MIN/MAX of booleans.
Post by Chris Burrows
The results of MIN and MAX are implementation-dependant. All the compiler
implementor has to do when the parameter to either function is a BOOLEAN is
a) return a BOOLEAN value
b) ensure that MIN(BOOLEAN) # MAX(BOOLEAN)
Why, really? The semantics of MIN/MAX of booleans is completely
arbitrary anyway.
Post by Chris Burrows
c) document the behaviour in the implementation-dependent section of the
compiler documentation.
No one would want to use or should use MIN/MAX of booleans other than
perhaps in a low-level module (using SYSTEM).
Post by Chris Burrows
If the report is changed as you suggest, that would
a) add the further complexity of error-handling to the compiler
b) break all existing compilers that conform to this part of the report.
If the report is left as it is, does it cause any problems for the end-user
of the compiler? I think not.
As the saying goes: "Any sufficiently old bug becomes a feature."

August
Ulrich
2005-08-10 17:40:59 UTC
Permalink
Post by akarl
Hi all,
My interpretation of section 10.3 (Predeclared Procedures) of the
Oberon-2 report (March '95) is that MAX and MIN are defined for any
basic type, which of course is wrong since MAX(BOOLEAN) and MIN(BOOLEAN)
doesn't make sense. I think
Name Argument type ...
MAX(T) T = basic type ...
T = SET ...
MIN(T) T = basic type ...
T = SET ...
should be changed to
Name Argument type ...
MAX(T) T = numeric type or CHAR ...
T = SET ...
MIN(T) T = numeric type or CHAR ...
T = SET ...
Comments?
Regards,
August
Hallo August

Vielen Dank für Dein präzises Beobachten und Deinen Beitrag.

Ein gutes Mittel, um Fragen bzgl. Oberon zu klären, ist ein Blick in die offiziellen Definitionen in "Programming in Oberon"
(Reiser, Wirth) und "Project Oberon" (Gutknecht, Wirth). In PIM ist MIN/MAX für BOOLEAN definiert, man kann BOOLEAN aber nur auf
Gleichheit und Ungleichheit testen. In PO ist in Einklang mit der Sprachdefinition MIN/MAX für BOOLEAN implementiert:
MIN(BOOLEAN) = 0, MAX(BOOLEAN) = 1 (Seiten 419 und 420, OCE.StPar1).

Deine Frage ist nicht nur für Übersetzerbauer von essentieller Bedeutung, denn das automatische Initialisieren des Speichers ist
untrennbar mit den Werten verbunden, die Variablen annehmen können. Konkret heißt das: Boolesche Variablen sind auf FALSE
initialisiert.

Da MIN(<Typ>) < MAX(<Typ>) gilt, was die tatsächlichen Werte angeht, liegt weder ein Fehler noch eine Ungenauigkeit vor, auch
wenn man Boolesche Variablen nicht mit Ordnungsoperatoren in Relation setzen kann.

Mich würde noch interessieren, warum Du Dich so genau damit beschäftigst, was ich lobenswert finde. Die meisten Programmierer
passen sich dem Übersetzer an, den sie gerade benutzen, und machen sich keine Gedanken, ob dieser Übersetzer die Sprache richtig
abbildet.
akarl
2005-08-11 01:40:56 UTC
Permalink
Post by Ulrich
Post by akarl
Hi all,
My interpretation of section 10.3 (Predeclared Procedures) of the
Oberon-2 report (March '95) is that MAX and MIN are defined for any
basic type, which of course is wrong since MAX(BOOLEAN) and
MIN(BOOLEAN) doesn't make sense. I think
Name Argument type ...
MAX(T) T = basic type ...
T = SET ...
MIN(T) T = basic type ...
T = SET ...
should be changed to
Name Argument type ...
MAX(T) T = numeric type or CHAR ...
T = SET ...
MIN(T) T = numeric type or CHAR ...
T = SET ...
Comments?
Regards,
August
Hallo August
Vielen Dank für Dein präzises Beobachten und Deinen Beitrag.
Ein gutes Mittel, um Fragen bzgl. Oberon zu klären, ist ein Blick in die
offiziellen Definitionen in "Programming in Oberon" (Reiser, Wirth) und
"Project Oberon" (Gutknecht, Wirth). In PIM ist MIN/MAX für BOOLEAN
definiert, man kann BOOLEAN aber nur auf Gleichheit und Ungleichheit
testen. In PO ist in Einklang mit der Sprachdefinition MIN/MAX für
BOOLEAN implementiert: MIN(BOOLEAN) = 0, MAX(BOOLEAN) = 1 (Seiten 419
und 420, OCE.StPar1).
Deine Frage ist nicht nur für Übersetzerbauer von essentieller
Bedeutung, denn das automatische Initialisieren des Speichers ist
untrennbar mit den Werten verbunden, die Variablen annehmen können.
Konkret heißt das: Boolesche Variablen sind auf FALSE initialisiert.
Da MIN(<Typ>) < MAX(<Typ>) gilt, was die tatsächlichen Werte angeht,
liegt weder ein Fehler noch eine Ungenauigkeit vor, auch wenn man
Boolesche Variablen nicht mit Ordnungsoperatoren in Relation setzen kann.
Mich würde noch interessieren, warum Du Dich so genau damit
beschäftigst, was ich lobenswert finde. Die meisten Programmierer passen
sich dem Übersetzer an, den sie gerade benutzen, und machen sich keine
Gedanken, ob dieser Übersetzer die Sprache richtig abbildet.
As I think someone has pointed out in this thread, the issue is of
little practical importance. It was just an inconsistency I found in the
Oberon report. (I'm an INTP personality, you know ;-)

August
Ulrich
2005-08-11 14:20:06 UTC
Permalink
Post by akarl
As I think someone has pointed out in this thread, the issue is of
little practical importance. It was just an inconsistency I found in the
Oberon report. (I'm an INTP personality, you know ;-)
August
Genau diesem Eindruck wollte ich entgegen wirken: Es liegt weder eine Inkonsistenz noch eine Ungenauigkeit vor. Und ohne
praktische Bedeutung ist es nur für eine bestimmte Klasse von Programmen, die keine Booleschen Werte benutzen. Meine Programme
zählen beispielsweise nicht dazu, ebenso nicht die Programme, die in PO veröffentlicht wurden.
Loading...