Discussion:
Set elements out of range
(too old to reply)
August Karlstrom
2017-09-13 12:52:03 UTC
Permalink
In Oberon-07/16, is the operator IN supposed to handle elements which
are out of range, for instance 10000 IN A? Or is the result undefined?

Regards,
August
c***@gmail.com
2017-09-15 12:11:04 UTC
Permalink
Post by August Karlstrom
In Oberon-07/16, is the operator IN supposed to handle elements which
are out of range, for instance 10000 IN A? Or is the result undefined?
Since Revision 1.10.2013 / 18.3.2015 of the 'Programming Language Oberon' the values of a SET have been defined as "the sets of integers between 0 and an implementation-dependent limit". The result of 10000 IN A might not be out of range for a particular implementation. You would need to check the implementation-specific documentation or contact technical support for the compiler you are using if you want an answer to your question.

In the case of the current Astrobe Oberon compilers for ARM Cortex-M3, M4 and M7, and FPGA RISC5 targets, the limit is 31. No compile time or runtime error results if a value greater than 31 is used in an IN expression, but the result of that expression is not defined.

Regards,
Chris Burrows
CFB Software
http://www.astrobe.com
August Karlstrom
2017-09-15 14:24:55 UTC
Permalink
Post by c***@gmail.com
Post by August Karlstrom
In Oberon-07/16, is the operator IN supposed to handle elements which
are out of range, for instance 10000 IN A? Or is the result undefined?
Since Revision 1.10.2013 / 18.3.2015 of the 'Programming Language Oberon' the values of a SET have been defined as "the sets of integers between 0 and an implementation-dependent limit". The result of 10000 IN A might not be out of range for a particular implementation. You would need to check the implementation-specific documentation or contact technical support for the compiler you are using if you want an answer to your question.
Indeed, I am familiar with all of this.
Post by c***@gmail.com
In the case of the current Astrobe Oberon compilers for ARM Cortex-M3, M4 and M7, and FPGA RISC5 targets, the limit is 31. No compile time or runtime error results if a value greater than 31 is used in an IN expression, but the result of that expression is not defined.
That the value of {...}, INCL or EXCL is undefined for out-of-range
elements is somewhat expected. However, that `x IN A' may yield TRUE
even though x is not a member of A is a bit surprising, to say the least.


-- August
c***@gmail.com
2017-09-16 00:02:22 UTC
Permalink
Post by August Karlstrom
That the value of {...}, INCL or EXCL is undefined for out-of-range
elements is somewhat expected. However, that `x IN A' may yield TRUE
even though x is not a member of A is a bit surprising, to say the least.
Avoid making assumptions about anything that is not explicitly stated unless you like having surprises ;-)

I would not expect programmers to be testing if a value was contained in a set if they knew (which they should) that it was not possible to include that value in a set. If they were I would be very suspicious that they had some basic errors of logic in other, dependent, parts of their program.

When using Oberon, assertions should be used at strategic points in a program to detect invalid data and trap it at source.

Chris.
August Karlstrom
2017-09-16 09:06:48 UTC
Permalink
Post by c***@gmail.com
Post by August Karlstrom
That the value of {...}, INCL or EXCL is undefined for out-of-range
elements is somewhat expected. However, that `x IN A' may yield TRUE
even though x is not a member of A is a bit surprising, to say the least.
Avoid making assumptions about anything that is not explicitly stated unless you like having surprises ;-)
I would not expect programmers to be testing if a value was contained in a set if they knew (which they should) that it was not possible to include that value in a set. If they were I would be very suspicious that they had some basic errors of logic in other, dependent, parts of their program.
I encountered this problem when I tried to calculate the largest allowed
element in a set:

x, limit: INTEGER

x := 0;
REPEAT
INC(x)
UNTIL ~(x IN -{});
limit := x - 1
Post by c***@gmail.com
When using Oberon, assertions should be used at strategic points in a program to detect invalid data and trap it at source.
That is a good practice in any language which support assertions.


-- August
c***@gmail.com
2017-09-16 13:48:13 UTC
Permalink
Post by August Karlstrom
I encountered this problem when I tried to calculate the largest allowed
x, limit: INTEGER
x := 0;
REPEAT
INC(x)
UNTIL ~(x IN -{});
limit := x - 1
This is similar but should work:

s: SET;
i, limit: INTEGER;

s := -{};
i := -1;
REPEAT
INC(i);
EXCL(s, i)
UNTIL s = {};
limit := i;

Chris.
August Karlstrom
2017-09-16 14:12:40 UTC
Permalink
Post by c***@gmail.com
Post by August Karlstrom
I encountered this problem when I tried to calculate the largest allowed
x, limit: INTEGER
x := 0;
REPEAT
INC(x)
UNTIL ~(x IN -{});
limit := x - 1
s: SET;
i, limit: INTEGER;
s := -{};
i := -1;
REPEAT
INC(i);
EXCL(s, i)
UNTIL s = {};
limit := i;
That's clever, thanks!

-- August

Loading...