Discussion:
Assignment to pointer and procedure value parameters
(too old to reply)
August Karlstrom
2017-02-12 15:02:39 UTC
Permalink
To me it is not clear if assignments to value parameters of pointer or
procedure type are permitted. Section 9.1 says

"If a value parameter is structured (of array or record type), no
assignment to it or to its elements are permitted."

This indicates that structured value parameters of pointer or procedure
type may be assigned to. However, section 10.1 says

"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."

This means that only value parameters of a basic type can be assigned
to. Thus, there is a contradiction between the two sections.

https://www.inf.ethz.ch/personal/wirth/Oberon/Oberon07.Report.pdf


-- August
Richard
2017-02-12 17:03:19 UTC
Permalink
Post by August Karlstrom
"If a value parameter is structured (of array or record type), no
assignment to it or to its elements are permitted."
Interesting restriction, which AFAIK has not been there in earlier
versions of Oberon. It allows the optimization of passing only the
addresses of structured value parameters instead of having to copy all
elements.
Post by August Karlstrom
This indicates that structured value parameters of pointer or procedure
type may be assigned to. However, section 10.1 says
I don't think that pointer or procedure types are considered to be
structured values.
Post by August Karlstrom
"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."
This means that only value parameters of a basic type can be assigned
to. Thus, there is a contradiction between the two sections.
No contradiction if pointer and procedure types are considered to be
basic types.

Richard
August Karlstrom
2017-02-12 22:25:29 UTC
Permalink
Post by Richard
Post by August Karlstrom
"If a value parameter is structured (of array or record type), no
assignment to it or to its elements are permitted."
Interesting restriction, which AFAIK has not been there in earlier
versions of Oberon. It allows the optimization of passing only the
addresses of structured value parameters instead of having to copy all
elements.
Correct. However, if I remember correctly the restriction has been there
since the revision of Oberon in 2007, at first with the CONST keyword
which was then dropped.
Post by Richard
Post by August Karlstrom
This indicates that structured value parameters of pointer or procedure
type may be assigned to. However, section 10.1 says
I don't think that pointer or procedure types are considered to be
structured values.
Maybe you are right. There used to be a non-terminal symbol named
StrucType in the grammar:

StrucType = ArrayType | RecordType | PointerType | ProcedureType.

Now there is no mentioning of structured types in the grammar.
Post by Richard
Post by August Karlstrom
"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."
This means that only value parameters of a basic type can be assigned
to. Thus, there is a contradiction between the two sections.
No contradiction if pointer and procedure types are considered to be
basic types.
But they aren't. The basic types are atomic (see section 6.1).


-- August
c***@gmail.com
2017-02-13 11:17:41 UTC
Permalink
Post by August Karlstrom
Post by Richard
No contradiction if pointer and procedure types are considered to be
basic types.
But they aren't. The basic types are atomic (see section 6.1).
Section 6.1 only lists the basic types that "are denoted by predeclared identifiers" - it does NOT state that they are the ONLY basic types. e.g. given the declaration:

TYPE Int32 = INTEGER;

Int32 is a basic type, but Int32 is not a predeclared identifier.

Additionally:

"Pointers, i.e. values of pointer types, are themselves not structured ..."

Ref: N.Wirth, Programming in Oberon, 2014

If the only types are "basic types" and "structured types" and pointer types are not structured types then they must be basic types.

I have seen nothing that states that assignments to value parameters of pointer or procedure type are not permitted so can only conclude that they are permitted.

Regards,
Chris Burrows
CFB Software
http://www.astrobe.com
August Karlstrom
2017-02-13 15:45:20 UTC
Permalink
On Monday, February 13, 2017 at 8:55:30 AM UTC+10:30, August
Post by August Karlstrom
Post by Richard
No contradiction if pointer and procedure types are considered to
be basic types.
But they aren't. The basic types are atomic (see section 6.1).
Section 6.1 only lists the basic types that "are denoted by
predeclared identifiers" - it does NOT state that they are the ONLY
TYPE Int32 = INTEGER;
Int32 is a basic type, but Int32 is not a predeclared identifier.
Yes, of course. It's a type alias.
"Pointers, i.e. values of pointer types, are themselves not
structured ..."
Ref: N.Wirth, Programming in Oberon, 2014
Still, recently

StrucType = ArrayType | RecordType | PointerType | ProcedureType.

was part of the grammar. He must have changed his mind on what a
structured type is.
If the only types are "basic types" and "structured types" and
pointer types are not structured types then they must be basic
types.
To my mind a basic type is a type which is not based on any other type.
Both pointer and procedure types are based on other types.
I have seen nothing that states that assignments to value parameters
of pointer or procedure type are not permitted so can only conclude
that they are permitted.
You are probably right. In a previous revision of the language report it
was stated that a value parameter of *scalar* type represents a local
variable, but it was changed to *basic* type.


-- August
c***@gmail.com
2017-02-13 20:47:03 UTC
Permalink
Post by August Karlstrom
To my mind a basic type is a type which is not based on any other type.
Both pointer and procedure types are based on other types.
From a pragmatic point of view, In this context (i.e. value parameters) a structured type is one that requires multiple sequences of instructions to make a copy of the actual parameter. A basic type is any type that is not a structured type. Both pointers and procedure types are simply addresses.

Note that the RETURN statement has a similar restriction regarding structured types for similar reasons.

Regards,
Chris
August Karlstrom
2017-02-14 09:35:27 UTC
Permalink
On Tuesday, February 14, 2017 at 2:15:21 AM UTC+10:30, August
Post by August Karlstrom
To my mind a basic type is a type which is not based on any other
type. Both pointer and procedure types are based on other types.
From a pragmatic point of view, In this context (i.e. value
parameters) a structured type is one that requires multiple
sequences of instructions to make a copy of the actual parameter. A
basic type is any type that is not a structured type.
In other words a basic type is a scalar type and vice versa.
Both pointers and procedure types are simply addresses.
Indeed.
Note that the RETURN statement has a similar restriction regarding
structured types for similar reasons.
You mean the RETURN *clause* :-)

Regards,
August

Loading...