[Oberon] Assignment to value parameters of pointer or procedure type
Werner Heiz
werner.heiz at gmail.com
Sun Feb 9 14:58:50 CET 2025
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 at 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 at lists.inf.ethz.ch mailing list for ETH Oberon and related systems
> https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list