Assignment to value parameters of pointer or procedure type
According to the Oberon-07 language reference from 2013-10-01 a scalar value parameter can be assigned to since it's just a local variable: "A value parameter corresponds to an actual parameter that is an expression, and it stands for its value, which cannot be changed by assignment. However, if a value parameter is of a scalar type, it represents a local variable to which the value of the actual expression is initially assigned." In the edition from 2015-03-18 "scalar type" was changed to "basic type": "A value parameter corresponds to an actual parameter that is an expression, and it stands for its value, which cannot be changed by assignment. However, if a value parameter is of a basic type, it represents a local variable to which the value of the actual expression is initially assigned." If I interpret this correctly a value parameters of pointer or procedure type cannot be assigned to. This procedure, for instance, is then invalid: PROCEDURE Length(t: List): INTEGER; VAR n: INTEGER; BEGIN n := 0; WHILE t # NIL DO INC(n); t := t.next END RETURN n END Length Instead we need to introduce an extra local variable to step through the list: PROCEDURE Length(t: List): INTEGER; VAR n: INTEGER; p: List; BEGIN n := 0; p := t; WHILE p # NIL DO INC(n); p := p.next END RETURN n END Length Does anyone know why "scalar type" was changed to "basic type". If my memory serves me correctly this has been discussed before but right now I cannot find the thread. /August
In my view the term basic type is broader than scalar type and includes pointer and procedure types. So, I think your initial example is valid. In Pascal and Modula-2 structured types were actually copied and you could change them without effecting the original values. In Oberon only addresses similar to VAR parameters are transferred, thus assignment is not allowed in these cases. Is t.field := 77 allowed? In my view, yes. If t was the record itself and not a pointer, no. This is very subtle, because the dereferencing ^ can be omitted if t is a pointer to a record. Werner Heiz Von meinem iPad gesendet
Am 09.02.2025 um 05:15 schrieb August Karlstrom <fusionfile@gmail.com>:
According to the Oberon-07 language reference from 2013-10-01 a scalar value parameter can be assigned to since it's just a local variable:
"A value parameter corresponds to an actual parameter that is an expression, and it stands for its value, which cannot be changed by assignment. However, if a value parameter is of a scalar type, it represents a local variable to which the value of the actual expression is initially assigned."
In the edition from 2015-03-18 "scalar type" was changed to "basic type":
"A value parameter corresponds to an actual parameter that is an expression, and it stands for its value, which cannot be changed by assignment. However, if a value parameter is of a basic type, it represents a local variable to which the value of the actual expression is initially assigned."
If I interpret this correctly a value parameters of pointer or procedure type cannot be assigned to. This procedure, for instance, is then invalid:
PROCEDURE Length(t: List): INTEGER; VAR n: INTEGER; BEGIN n := 0; WHILE t # NIL DO INC(n); t := t.next END RETURN n END Length
Instead we need to introduce an extra local variable to step through the list:
PROCEDURE Length(t: List): INTEGER; VAR n: INTEGER; p: List; BEGIN n := 0; p := t; WHILE p # NIL DO INC(n); p := p.next END RETURN n END Length
Does anyone know why "scalar type" was changed to "basic type". If my memory serves me correctly this has been discussed before but right now I cannot find the thread.
/August -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
Pointers and procedure variables are of basic types. In an old email Wirth confirmed that the terms basic and scalar types were synonyms. Wirth's intention was to pass only structured types (array and records) as read-only references in the case of value parameters. In Differences between Revised Oberon and Oberon: "[...] we postulate that if a value parameter is if a structured type, no assignments are possible. Hence, the parameter can be passed by a reference like in the case of VAR parameters." PIO: "If a parameter of a structured type is specified without the symbol VAR, it is considered to be "read-only", i.e. no assignments to it are allowed." Unfortunately only in the report he mentions basic types as the ones to be copied to a local variable, that may cause confusion since there is an explicit list on the Report (that excludes pointers and procedure variables). However by reading PIO: "Types are classified into unstructured and structured types. Each type essentially defines the set of values which a variable of this type may assume. A value of an unstructured type is an atomic unit, whereas a value of structured type has components (elements). For example, the type INTEGER is unstructured; its elements are atomic. It does not make sense, e.g. to refer to the third bit of the value 13; the circumstance that a number may "have a third bit", or a second digit, is a characteristic of its (internal) representation, which intentionally is to remain unknown." And later (just as confirmation): "Pointers, i.e. values of pointer types, are themselves not structured, but rather are used to establish relationships [...]" Based on his definition of unstructured and structured types, also procedure variables are of basic type, since they have no components (like arrays and records). -- Diego Sardina
On 2025-02-09 15:00, Diego Sardina wrote:
Pointers and procedure variables are of basic types.
In an old email Wirth confirmed that the terms basic and scalar types were synonyms.
Thanks for the clarification. Actually, the first sentence in section 6.1. says "The following basic types are denoted by predeclared identifiers." The wording indicates that there are other basic types even if it doesn't explicitly say that the additional ones are pointer and procedure types. Previously I was under the impression that the basic types were exactly the ones mentioned in section 6.1. https://miasap.se/obnc/oberon-report.html#sec6.1 /August
It really depends on the version of Oberon at hand: * The original Oberon report states in Section 6 that "Such association may be with unstructured (basic) types, or it may be with structured types [...]. There are two different structures, namely arrays and records [...]." It follows that basic types are synonymous with unstructured types which are thus all types except arrays and records. This is consistent with the aforementioned non-exclusive wording of the first sentence in Section 6.1 which reads "The following basic types are denoted by predeclared identifiers." * Oberon-07 keeps the same wording in Section 6.1 but unfortunately does no longer contain the clarifying equality of unstructured and basic types. This leaves room for interpretation and confusion. * Oberon-2 on the other hand also drops that equality but makes it absolutely clear in the first sentence of Section 6.1 that "The basic types are denoted by predeclared identifiers." This is also consistent with the overall structure of Section 6 which distinguishes between basic, array, record, pointer, and procedure types. Procedure and pointer types are unstructured and thus basic in the original Oberon and maybe in Oberon-07, but clearly not in Oberon-2. On 09/02/2025 15:59, August Karlstrom wrote:
On 2025-02-09 15:00, Diego Sardina wrote:
Pointers and procedure variables are of basic types.
In an old email Wirth confirmed that the terms basic and scalar types were synonyms.
Thanks for the clarification. Actually, the first sentence in section 6.1. says "The following basic types are denoted by predeclared identifiers." The wording indicates that there are other basic types even if it doesn't explicitly say that the additional ones are pointer and procedure types. Previously I was under the impression that the basic types were exactly the ones mentioned in section 6.1.
https://miasap.se/obnc/oberon-report.html#sec6.1
/August -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On 2025-02-09 16:48, Florian Negele wrote:
Procedure and pointer types are unstructured and thus basic in the original Oberon and maybe in Oberon-07, but clearly not in Oberon-2.
Maybe it's better then to use the terms "scalar type" and "predeclared type" respectively to avoid confusion. The language report says that the second parameter of SYSTEM.GET and SYSTEM.PUT can be "any basic type" which I then interpret as any predeclared type or any pointer or procedure type, i.e. any scalar type. For SYSTEM.VAL it says "scalar" and it's not clear to me why the wording is different here. https://miasap.se/obnc/oberon-report.html#sec11.1 I also noticed that in the Project Oberon compiler there seems to be no type checking of the second parameter, for instance this module compiles despite a and r being non-scalar parameters: MODULE Test; IMPORT SYSTEM; VAR a: ARRAY 10 OF INTEGER; r: RECORD END; BEGIN SYSTEM.GET(0, a); SYSTEM.GET(0, r) END Test. /August
On Sat, Feb 15, 2025 at 11:07 PM August Karlstrom <fusionfile@gmail.com> wrote:
For SYSTEM.VAL it says "scalar" and it's not clear to me why the wording is different here.
IMHO it is to exclude BOOLEAN which is a "basic type" but not a "scalar
type". That also leads to a plausible answer to your original question in this discussion as to why "scalar type" was changed to "basic type" in Section 10.1 i.e. to allow for BOOLEAN value parameters. -- Regards, Chris Burrows CFB Software https://www.astrobe.com
participants (5)
-
August Karlstrom -
Chris Burrows -
Diego Sardina -
Florian Negele -
Werner Heiz