Recursive declarations #1195
Replies: 2 comments
-
(I don't play with Modula-3 since long, so my consideration could be totally wrong) The Modula-3 definition works well if we consider the expansion only within the recursive declaration, especially where N occurs. Other declarations in the same living scope are already considered expanded, so I doesn't need to be expanded (only the type E if that contains N). N can't occur in I (it would be impossible to expand), so we expect it to be expanded elsewhere. |
Beta Was this translation helpful? Give feedback.
-
Yes, I am seeing it is necessary to do some expanding inside the Initializing expression itself when a variable declaration has This like examples 4 & 5 has recursions that would require an equation solver in some strange algebra to infer types for How to generalize expanding an expression and its internal types is not clear to me. Maybe it can ignore further expansion of operations like subscripting and field selection that narrow down what is to be expanded. BTW, CM3 flags example 6. |
Beta Was this translation helpful? Give feedback.
-
For some time, I have struggled to interpret Modula-3's definition
of recursive declarations in the case of a variable declaration with
no explicit type, the type to be taken from the initial value expression.
Here is the definition in 2.4.8, with emphasis on the problematic part:
A constant, type, or procedure declaration N = E, a variable declaration N: E,
an exception declaration N(E), or a revelation N = E is recursive if N occurs
in any partial expansion of E. A variable declaration N := I where the type is
omitted is recursive if N occurs in any partial expansion of the type E of I.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here are 5 examples that intuitively should not be allowed. All 5 are flagged
by CM3 as illegal recursive declarations.
10 (* Example 3: )
11 ; V8 : [ 0 .. BITSIZE ( V8 ) ]
12
13 ( Example 4: )
14 ; TYPE R = RECORD F : [ 0 .. BITSIZE ( V5 ) ] END
15 ; VAR V4 : R
16 ; VAR V5 := V4 . F
17
18 ( Example 5: *)
19 ; TYPE R2 = RECORD F2 : [ 0 .. BITSIZE ( V7 ) ] END
20 ; TYPE P = REF R2
21 ; TYPE A = ARRAY CHAR OF P
22 ; VAR V6 : A
23 ; VAR V7 := V6 [ 'x' ] ^ . F2
24
Reading the definition carefully, in examples 1 & 2, type E doesn't exist
at all, so its expansions could not lead back to N, so no recursion exists as
defined. Examples 4 & 5 have to expand E first, to find E, before expanding
it.
It seems to me this should say something like:
... if N occurs in any partial expansion of I or of the type I of E.
Either way, I has to be expanded, first to look for N within,
or second to derive E, so E can be expanded. And maybe the meaning
of expanding an expression I needs a different term or further definition.
Any thoughts?
Beta Was this translation helpful? Give feedback.
All reactions