<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">> Le 12/10/2017 à 01:51, Stéphane Aulery a écrit:</span><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">><br class=""></span></font><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">> M and M2 are valid but M1, M3, M4 and M5 are invalid, </span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">so it seems inconsistent in fact. No?</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">></span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">Unfortunately it is a little unclear what the current Oberon-07 language *specification* available</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">at </span><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><a href="http://www.inf.ethz.ch/personal/wirth" class="">www.inf.ethz.ch/personal/wirth</a></span></font><span style="font-family: monospace; white-space: pre-wrap;" class=""> implies when it comes to assignments. </span><span style="font-family: monospace; white-space: pre-wrap;" class="">In </span><span style="font-family: monospace; white-space: pre-wrap;" class="">ch. 9.1. of the language</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">report</span><span style="font-family: monospace; white-space: pre-wrap;" class="">, t</span><span style="font-family: monospace; white-space: pre-wrap;" class="">he assignment rules for an </span><span style="font-family: monospace; white-space: pre-wrap;" class="">assignment "designator := expression” are defined as follows:</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">"The type of the expression must be the SAME as that of the designator. </span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">The following exceptions hold:</span></div><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> 1. The constant NIL can be assigned to variables of any pointer or procedure type.<br class=""> 2. Strings can be assigned to any array of characters, provided the number of</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> characters in the string is less than that of the array. (A null character is</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> appended). </span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">Single-character strings can</span><span style="white-space: pre-wrap; font-family: monospace;" class=""> </span><span style="white-space: pre-wrap; font-family: monospace;" class="">also be assigned to variables of type CHAR.</span></div><div class=""><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> 3. In the case of records, the type of the source must be an extension of the type of</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> the destination. 4. An open array may be assigned to an array of equal base type.”</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">while in ch. 6.5 of the report the assignment rules for procedures are specified as follows:</span></font></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class=""><br class=""></span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">"If a procedure </span><span style="white-space: pre-wrap; font-family: monospace;" class="">P </span><span style="white-space: pre-wrap; font-family: monospace;" class="">is assigned to</span><span style="white-space: pre-wrap; font-family: monospace;" class=""> </span><span style="white-space: pre-wrap; font-family: monospace;" class="">a procedure variable of type </span><span style="white-space: pre-wrap; font-family: monospace;" class="">T</span><span style="white-space: pre-wrap; font-family: monospace;" class="">, the (types of the) formal</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">parameters of </span><span style="white-space: pre-wrap; font-family: monospace;" class="">P </span><span style="white-space: pre-wrap; font-family: monospace;" class="">must be the same as those</span><span style="white-space: pre-wrap; font-family: monospace;" class=""> </span><span style="white-space: pre-wrap; font-family: monospace;" class="">indicated in the formal parameters of</span><span style="white-space: pre-wrap; font-family: monospace;" class=""> </span><span style="white-space: pre-wrap; font-family: monospace;" class="">T</span><span style="white-space: pre-wrap; font-family: monospace;" class="">. The same</span></div><div class=""><span style="white-space: pre-wrap; font-family: monospace;" class="">holds for the result type in the case of a function procedure."</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""><br class=""></span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""><br class=""></span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">However, the above rules</span></font><span style="font-family: monospace; white-space: pre-wrap;" class=""> do not actually specify what exactly is meant by the “same" type.</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">But the *</span></font><span style="white-space: pre-wrap; font-family: monospace;" class="">current* implementation of the Oberon-07 compiler, which is also available </span><span style="font-family: monospace; white-space: pre-wrap;" class="">at</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><a href="http://www.inf.ethz.ch/personal/wirth" class="">www.inf.ethz.ch/personal/wirth</a> </span></font><span style="font-family: monospace; white-space: pre-wrap;" class="">implements the following rules for *same* types</span><span style="font-family: monospace; white-space: pre-wrap;" class="">:</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> Same types</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> Two variables *a* and *b* with types *Ta* and *Tb* are of the *same type* if</span><br style="font-family: monospace; white-space: pre-wrap;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> 1. *Ta* and *Tb* are both denoted by the same type identifier, or</span><br style="font-family: monospace; white-space: pre-wrap;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> 2. *Ta* is declared to equal *Tb* in a type declaration of the form *Ta* = *Tb*, or</span><br style="font-family: monospace; white-space: pre-wrap;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> 3. *a* and *b* appear in the same identifier list in a variable, record field, or</span><br style="font-family: monospace; white-space: pre-wrap;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> </span><span style="font-family: monospace; white-space: pre-wrap;" class="">formal parameter declaration and are not open arrays, or</span><br style="font-family: monospace; white-space: pre-wrap;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> 4. *Ta* and *Tb* are array types with same element types and length.</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">Thus, for array and procedures *structural equivalence* suffices, whereas </span><span style="font-family: monospace; white-space: pre-wrap;" class="">for </span><span style="font-family: monospace; white-space: pre-wrap;" class="">records</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">structural equivalence does not suffice (in the *current* implementation of the</span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class="">compiler), as</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> can </span><span style="font-family: monospace; white-space: pre-wrap;" class="">easily be seen by compiling the following small test program:</span></div><div class=""><br class=""></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> MODULE M; (*test of the implementation of Oberon-07 as of 12.10.17*)<br class=""> </span></font><span style="white-space: pre-wrap; font-family: monospace;" class=""> </span><span style="white-space: pre-wrap; font-family: monospace;" class="">VAR</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> p, q: ARRAY 10 OF INTEGER;<br class=""> r, s: ARRAY 10 OF INTEGER;</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> e, f: PROCEDURE (i, j: INTEGER);<br class=""> g, h: PROCEDURE (i, j: INTEGER);</span></font></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> </span><span style="font-family: monospace; white-space: pre-wrap;" class="">a</span><span style="font-family: monospace; white-space: pre-wrap;" class="">, </span><span style="font-family: monospace; white-space: pre-wrap;" class="">b</span><span style="font-family: monospace; white-space: pre-wrap;" class="">: </span><span style="font-family: monospace; white-space: pre-wrap;" class="">RECORD</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> </span><span style="font-family: monospace; white-space: pre-wrap;" class="">i</span><span style="font-family: monospace; white-space: pre-wrap;" class="">, </span><span style="font-family: monospace; white-space: pre-wrap;" class="">j</span><span style="font-family: monospace; white-space: pre-wrap;" class="">: </span><span style="font-family: monospace; white-space: pre-wrap;" class="">INTEGER</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> </span><span style="font-family: monospace; white-space: pre-wrap;" class="">END</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> ;</span><br style="font-family: monospace; white-space: pre-wrap;" class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""> </span><span style="font-family: monospace; white-space: pre-wrap;" class="">c</span><span style="font-family: monospace; white-space: pre-wrap;" class="">, </span><span style="font-family: monospace; white-space: pre-wrap;" class="">d</span><span style="font-family: monospace; white-space: pre-wrap;" class="">: </span><span style="font-family: monospace; white-space: pre-wrap;" class="">RECORD</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> </span><span style="font-family: monospace; white-space: pre-wrap;" class="">i</span><span style="font-family: monospace; white-space: pre-wrap;" class="">, </span><span style="font-family: monospace; white-space: pre-wrap;" class="">j</span><span style="font-family: monospace; white-space: pre-wrap;" class="">: </span><span style="font-family: monospace; white-space: pre-wrap;" class="">INTEGER</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> </span><span style="font-family: monospace; white-space: pre-wrap;" class="">END</span><span style="font-family: monospace; white-space: pre-wrap;" class=""> ;</span></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""> BEGIN<br class=""> p := q; (*ok -> same array types*)<br class=""> p := r; (*ok -> structural equivalence suffices*)<br class=""> e := f; (*ok -> same procedure types*)<br class=""> e := g; (*ok -> structural equivalence suffices*)<br class=""> a := b; (*ok -> same record types*)<br class=""> a := c (*illegal assignment -> no structural equivalence for records*)<br class=""> END M.</span></font></div></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""></span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class="">-AP</span></font></div><div class=""><font face="monospace" class=""><span style="white-space: pre-wrap;" class=""><br class=""><br class=""></span><br class=""></font></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""><br class=""></span></div><div class=""><span style="font-family: monospace; white-space: pre-wrap;" class=""><br class=""></span></div></div></body></html>