Oberon Report Update 2016-05-01

Topics related to the use of Oberon language features
augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Mon May 02, 2016 10:29 am

cfbsoftware wrote:
Stefano wrote:Isn't REAL a predeclared type so that REAL = INTEGER is a redeclaration?
It's a predefined type e.g. like ABS. It is not a reserved word like BEGIN. e.g. in earlier versions of Oberon-07 you could have written:

PROCEDURE REAL(i: INTEGER);
BEGIN
END REAL;
As far as I understand the above declaration should be valid also in the current version of Oberon-07. REAL is just a predefined identifier and, if I understand it correctly, any predefined identifier can be redefined (as a constant, type, variable or procedure).

cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Mon May 02, 2016 11:23 am

august wrote:As far as I understand the above declaration should be valid also in the current version of Oberon-07. REAL is just a predefined identifier and, if I understand it correctly, any predefined identifier can be redefined (as a constant, type, variable or procedure).
That is correct. When I said they could be redefined in older versions of Oberon I meant as well as, not instead of, the current version. The explanation is based on the scoping rules. The key point here is that the standard identifiers of Oberon are considered to be declared in an imaginary scope enclosing the program. These can be redefined in the scope of a Module and can be further redefined within the scope of a Procedure.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Mon May 02, 2016 2:21 pm

In the latest revision "an open array may be assigned to an array of equal base type" but what about the other way around: Can an open array be the target of an assignment? After all, when a formal parameter is an open array a corresponding actual parameter can be an array of any length.

kevinhely
Posts: 29
Joined: Wed May 18, 2011 3:35 am

Re: Oberon Report Update 2016-05-01

Post by kevinhely » Mon May 02, 2016 6:45 pm

Can an open array be the target of an assignment?
From the Report: "The type of the expression must be the same as that of the designator" and "Strings can be assigned to any array of characters..."

Here's a question: if an open array is assigned to an array of equal base type but shorter length, is this a run-time error?

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Mon May 02, 2016 8:18 pm

kevinhely wrote:
Can an open array be the target of an assignment?
From the Report: "The type of the expression must be the same as that of the designator" and "Strings can be assigned to any array of characters..."
What I mean is: Can a variable of type ARRAY n OF T or ARRAY OF T be assigned to a variable of type ARRAY OF T?
kevinhely wrote:Here's a question: if an open array is assigned to an array of equal base type but shorter length, is this a run-time error?
Assigning a string to an open array which doesn't fit should result in a run-time error. Therefor I conclude that it should be the same in the general case. No silent truncation in other words.

cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Tue May 03, 2016 4:10 am

augustk wrote:What I mean is: Can a variable of type ARRAY n OF T or ARRAY OF T be assigned to a variable of type ARRAY OF T?
No.
kevinhely wrote:Here's a question: if an open array is assigned to an array of equal base type but shorter length, is this a run-time error?
How this situation is handled depends on the implementation. e.g. Normal modules that have been compiled using the latest Project Oberon 2013 compiler result in termination with a trap at runtime. However, when standalone modules (e.g. the bootloader) are compiled runtime checks are disabled and no errors are reported.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Tue May 03, 2016 5:44 am

cfbsoftware wrote:
augustk wrote:What I mean is: Can a variable of type ARRAY n OF T or ARRAY OF T be assigned to a variable of type ARRAY OF T?
No.
But why can open array be the source of an assignment then? I can't see the reason for allowing open arrays to be the source of an assignment but not the target (of a variable parameter). Please, enlighten me. In the sentence "An open array may be assigned to an array of equal base type" the phrase "an array of equal base type" can be interpreted as either a "closed" array or an open array.

cfbsoftware
Site Admin
Posts: 525
Joined: Fri Dec 31, 2010 12:30 pm
Contact:

Re: Oberon Report Update 2016-05-01

Post by cfbsoftware » Tue May 03, 2016 12:05 pm

augustk wrote:But why can open array be the source of an assignment then?
Because Wirth decided to allow it as an exceptional case. You can see an example of its use in Modules.error in Project Oberon 2013.
augustk wrote:Please, enlighten me. In the sentence "An open array may be assigned to an array of equal base type" the phrase "an array of equal base type" can be interpreted as either a "closed" array or an open array.
This is my reasoning:

The general rule is: An array may be assigned to an array of equal base type and equal length.

There are four variations of possible exceptions to this rule that do not include the equal length requirement:

1. An open array may be assigned to an array of equal base type.
2. An array may be assigned to an open array of equal base type.
3. An array may be assigned to an array of equal base type.
4. An open array may be assigned to an open array of equal base type.

Only (1) has been identified as an allowable exception, so the conclusion is that (2), (3) and (4) are not allowed.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Sat May 14, 2016 3:53 pm

cfbsoftware wrote: The general rule is: An array may be assigned to an array of equal base type and equal length.
Only if the arrays have the same type.
cfbsoftware wrote: There are four variations of possible exceptions to this rule that do not include the equal length requirement:

1. An open array may be assigned to an array of equal base type.
2. An array may be assigned to an open array of equal base type.
3. An array may be assigned to an array of equal base type.
4. An open array may be assigned to an open array of equal base type.
By allowing strings to be assigned to (variable parameter) open character arrays we introduce a new kind of run-time error which occurs when the length of the destination array is too small. Once we have opened the possibility for such a run-time error I see no reason why we would allow 1 but not 2 and 4.Variation 3 is out of the question unless the arrays have been declared with the same type.

augustk
Posts: 54
Joined: Mon Sep 05, 2011 5:21 pm
Location: Sweden

Re: Oberon Report Update 2016-05-01

Post by augustk » Sat May 14, 2016 4:05 pm

augustk wrote:3. Open arrays can be assigned to arrays with the same base type.
If I understand it correctly, Wirth's own compiler only causes program abortion if the source array is longer than the destination array. As with strings, assigning a shorter array to a longer is accepted.

Post Reply