Clarifying type compatibility in Oberon-07
On Fri Oct 6 10:38:07 CEST 2017 August Karlstrom wrote
His reply was: "Yes, I consider this type compatibility as an addition to the language definition. I think it makes sense, and it is easy to implement."
I realize now that it is not really clear if he means that the structural equivalence is a "non-standard" feature, or if the language definition has changed, implying that every Oberon-07 compiler should work this way. What do you think?
This reply can be read either way - perhaps you can check back on this, just to be sure. But the last part ("makes sense, easy to implement”) seems to signal that there is (now) at least openness to the idea of changing the language itself. It’s perhaps worth inserting a historical comment at this point: There is of course a very long discussion history on this topic. Each time a new language (or at least a new compiler for an existing language) has been developed at ETH, this topic has came up. I remember having had to prepare an “informed point of view” (whatever that meant, presumably a list of pros and cons) for one of NW’s classes back in 1988 for the Oberon implementation on Ceres, which had then just come out. But even before that, this topic was periodically touched upon by various people, certainly in the contexts of the Modula on Lilith (1982) and the Pascal on PDP (1975) implementation projects that were all carried out at ETH. But surprisingly, despite this long discussion history and all the “grey brain matter" devoted to this important subject over all these years, a "final word" has never been spoken. Maybe an accident of history. Or perhaps people thought that it would somehow negatively impact code portability on different systems, or be difficult to implement - which it is not, as we now know. Or perhaps people simply didn't agree.. I just checked the source code of all these implementations and can say this: Historically, most Pascal, Modula and Oberon implementations (at least the ones realized at ETH) generally assume *name compatibility* as the basis for establishing type consistency. In each of these cases, there were/are only a small, but usually well-documented exceptions to this rule, for example open arrays, open array parameters and procedure parameters, where structural compatibility suffices. These were well justified exceptions to the rule (for example, otherwise every procedure used as an actual parameter would have to be given an explicit name, which was considered as too cumbersome - hence the exception). If it’s true that there now is a chance to change the Oberon language itself, we’re down to the question, whether it “makes sense”or not. That’s all there is to it. All arguments appear to be in the table. Jörg has made a few points on this topic in an earlier post ("currently a := b is not allowed for VAR a: ARRAY 10 OF CHAR; b: ARRAY 10 CHAR, because there are several ways to allow this already eg VAR a, b: ARRAY 10 OF CHAR"). On the other hand, I have also been working with Luca’s implementation of ORP (which fully implements structural equivalence for arrays) for some time now, I must say that I can’t see any issues with that. It works! (small addition: not so sure about portability when different compilers are used, perhaps someone else can chip in here). Personally I’m indifferent. I can live with the current status quo for arrays (where assignments of different ARRAY types are only allowed in the case of open arrays). But I would also accept a relaxation of the type equivalence rule in that case (knowing how easy it is to implement). Any additional thoughts? -AP
Personally I’m indifferent. I can live with the current status quo for arrays (where assignments of different ARRAY types are only allowed in the case of open arrays). But I would also accept a relaxation of the type equivalence rule in that case (knowing how easy it is to implement). Personally, I’m not indifferent ☺ I know that it can be done, but the question is WHY. Only because something can be done is a poor reason to do it. If you put a := b in your code, you do that as you know or assume a certain relationship between those two variables (they e.g. represent instances of the same or comparable thing). If this hold true, I don’t understand why you have to write two totally independent type declarations that (by accident) match structurally. br Jörg
On 2017-10-06 12:19, Andreas Pirklbauer wrote:
every procedure used as an actual parameter would have to be given an explicit name, > I'm not sure what you mean here. Can you clarify?
Personally I’m indifferent. I can live with the current status quo for arrays (where assignments of different ARRAY types are only allowed in the case of open arrays). But I would also accept a relaxation of the type equivalence rule in that case (knowing how easy it is to implement). I agree with this. I primarily just want to know which features I can rely on.
-- August
Short question: has anybody got an idea, how I could accomplish this? Thanks and regards, Dieter -- ____________________________________ Dr. Dieter Glötzel Im Rosengarten 27 64367 Mühltal Tel.: 06151 / 360 82 72
Hi Dieter the corresponding module in A2 looks like the following (below my signature). It should be widely applicable to ETHOberon for Windows because lot of Kernel32 is shared. Aside: Command.Context is the current's thread context. You don't have this in Oberon -- that should be the greatest difference. [In the current version of A2, the command context is stored Thread-locally and does not have to be explicitly coded, cf. module In or Out in the current version of A2]. Rgds Felix MODULE WinApplications; (* ll, fof : call windows applications from within WinAos *) (*ll, add statements for waiting process terminate in procedure Callprocess, 23.11.2007*) (*ll, add return result of CallProcess Procedure. IF resturn result = 0 THEN execution success END, 28.11.2007*) IMPORT Kernel32, KernelLog, Commands, Strings, SYSTEM, Options; PROCEDURE CallProcess( par: ARRAY OF CHAR; visible: BOOLEAN ): LONGINT; VAR bool: LONGINT; start: Kernel32.StartupInfo; pi: Kernel32.ProcessInformation; result: LONGINT; BEGIN result := -1; start.cb := SIZEOF( Kernel32.StartupInfo ); start.dwFlags := {Kernel32.StartFUseShowWindow}; IF visible THEN start.wShowWindow := 1; ELSE start.wShowWindow := 0; END; KernelLog.String( "Calling Windows Application: " ); KernelLog.String( par ); KernelLog.Ln; bool := Kernel32.CreateProcess( NIL , par, NIL , NIL , Kernel32.False, 0, NIL , NIL , start, pi ); result := Kernel32.WaitForSingleObject(pi.hProcess, Kernel32.Infinite); bool := Kernel32. GetExitCodeProcess(pi.hProcess, result); RETURN result END CallProcess; PROCEDURE Call*( CONST proc, par: ARRAY OF CHAR): LONGINT; VAR call: ARRAY 1024 OF CHAR; BEGIN call := '"'; Strings.Append (call, proc); Strings.Append (call, '" '); Strings.Append (call, par); RETURN CallProcess (call, TRUE); END Call; PROCEDURE Run*(context : Commands.Context); VAR options: Options.Options; visible: BOOLEAN; cmdpar: ARRAY 256 OF CHAR; res: LONGINT; BEGIN NEW (options); options.Add("h", "hide", Options.Flag); IF options.Parse(context.arg,context.error) THEN visible := ~options.GetFlag ("h"); ELSE visible := TRUE; END; context.arg.Ln (cmdpar); res := CallProcess (cmdpar, visible); IF res = 0 THEN KernelLog.String( "should have worked fine .... " ); KernelLog.Ln; ELSE KernelLog.String( "ERROR: " ); res:= Kernel32.GetLastError(); KernelLog.Int(res, 1 ); KernelLog.Ln; END; context.result := res; END Run; END WinApplications. SystemTools.Free WinApplications ~ System.Free WinApplications ~ ~ WinApplications.Run avrdude -help ~ Aos.Call WinApplications.Run avrdude -p m128 -c avrisp -P com1 -e ~ Aos.Call WinApplications.Run Notepad Test.bat ~ Aos.Call WinApplications.Run Test.bat ~ ~ EditTools.OpenAscii Test.Bat ~
Short question:
has anybody got an idea, how I could accomplish this?
Thanks and regards, Dieter
I have found and old email where I asked Prof. Wirth the following: "I would like to know the reasoning behind the departure from array name equivalence in favour of array structural equivalence. i.e these two types are equivalent in Oberon-07 but not in Oberon-90 TYPE A = ARRAY 3 OF INTEGER; B = ARRAY 3 OF INTEGER; Could you explain why you decided to change the language in this regard?" He replied saying that he does not remember the the exact circumstances, as the change was several years ago. He continued that the most obvious reason is that one needs less often to declare named types. So I agree with Артур Ефимов, probably Wirth will update the language report soon. The changes I made in ORP.Mod regarding arrays are to enable the assignment "i := j;" below MODULE Arrays2; TYPE T = ARRAY 3, 2 OF INTEGER; VAR a: ARRAY 4 OF T; b: ARRAY 4 OF T; i: ARRAY 4, 3, 2 OF INTEGER; j: ARRAY 4, 3, 2 OF INTEGER; BEGIN a := b; (* this works *) i := j; (* this should work, but illegal assignment in Wirth's Oberon *) END Arrays2. With the current ORP.Mod on Wirth's website, structural equivalence of arrays is half baked as it stops at the first array dimension. In my fix I use the following procedure, that does a full structural check. (* Type Rule I.1, I.2, I.4 *) PROCEDURE SameArrays(t0, t1: ORB.Type): BOOLEAN; BEGIN RETURN (t0 = t1) OR (t0.form = ORB.Array) & (t1.form = ORB.Array) & (t0.len = t1.len) & SameArrays(t0.base, t1.base) END SameArrays; Regards, Luca On Oct 6, 2017 06:57, "August Karlstrom" <fusionfile@gmail.com> wrote:
On 2017-10-06 12:19, Andreas Pirklbauer wrote:
every procedure used as an actual parameter would have to be given an explicit name, >
I'm not sure what you mean here. Can you clarify?
Personally I’m indifferent. I can live with the current status quo for
arrays (where assignments of different ARRAY types are only allowed in the case of open arrays). But I would also accept a relaxation of the type equivalence rule in that case (knowing how easy it is to implement).
I agree with this. I primarily just want to know which features I can rely on.
-- August -- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
On Fri, Oct 6, 2017, at 06:32 PM, Luca Boasso wrote:
I have found and old email where I asked Prof. Wirth the following:
"I would like to know the reasoning behind the departure from array name equivalence in favour of array structural equivalence. i.e these two types are equivalent in Oberon-07 but not in Oberon-90
TYPE A = ARRAY 3 OF INTEGER; B = ARRAY 3 OF INTEGER; Could you explain why you decided to change the language in this regard?"
He replied saying that he does not remember the the exact circumstances, as the change was several years ago. He continued that the most obvious reason is that one needs less often to declare named types.
During 2008 Wirth was experimenting structural equivalence in the case of arrays. Oberon-07 report of 1.11.2008 had this exception in 9.1. Assignments: --- 2. Arrays must have the same element type, and the length of the destination array must not be less than the length of the source array. --- This sentence was changed often in that period, maybe he was experimenting also structural equivalence between procedure variables. Later this sentence was removed, but he didn't update the compiler (I guess).
So I agree with Артур Ефимов, probably Wirth will update the language report soon.
I really hope that won't happen. If one wants structural equivalence then there is Modula-3. -- Diego Sardina
> So I agree with Артур Ефимов, probably Wirth will update the language report soon. I really hope that won't happen. If one wants structural equivalence then there is Modula-3. Hopefully, he will not do it. As explained I see no good reason to do so. Jörg
I am not a strong proponent of structural equivalence, I just want the report to be in sync with the compiler :) So either the report should reflect the compiler's rules or vice versa. On Oct 6, 2017 11:34, "Jörg" <joerg.straube@iaeth.ch> wrote:
> So I agree with Артур Ефимов, probably Wirth will update the language report soon.
I really hope that won't happen. If one wants structural equivalence then there is Modula-3.
Hopefully, he will not do it. As explained I see no good reason to do so. Jörg
-- Oberon@lists.inf.ethz.ch mailing list for ETH Oberon and related systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
-----Original Message----- From: Oberon [mailto:oberon-bounces@lists.inf.ethz.ch] On Behalf Of Diego Sardina Sent: Saturday, 7 October 2017 4:38 AM To: oberon@lists.inf.ethz.ch Subject: Re: [Oberon] Clarifying type compatibility in Oberon-07
On Fri, Oct 6, 2017, at 06:32 PM, Luca Boasso wrote:
I have found and old email where I asked Prof. Wirth the following:
"I would like to know the reasoning behind the departure from array name equivalence in favour of array structural equivalence. i.e these two types are equivalent in Oberon-07 but not in Oberon-90
TYPE A = ARRAY 3 OF INTEGER; B = ARRAY 3 OF INTEGER;
Could you explain why you decided to change the language in this regard?"
He replied saying that he does not remember the the exact circumstances, as the change was several years ago. He continued that the most obvious reason is that one needs less often to declare named types.
During 2008 Wirth was experimenting structural equivalence in the case of arrays.
Oberon-07 report of 1.11.2008 had this exception in 9.1. Assignments:
--- 2. Arrays must have the same element type, and the length of the destination array must not be less than the length of the source array. ---
This sentence was changed often in that period, maybe he was experimenting also structural equivalence between procedure variables.
Later this sentence was removed, but he didn't update the compiler (I guess).
As discussed in comp.lang.oberon he didn't update section 4.1 of the following document either: "Differences between Revised Oberon and Oberon". "But now we handle array and record assignments just like other assignments, writing dst := src, and discard the COPY procedure. The destination array must not be shorter than the source array. This is in accordance with the assignment rule for strings and with the compatibility of record types and their extensions." You can download a copy from: https://www.inf.ethz.ch/personal/wirth/Oberon/Oberon07.pdf This was explained in more detail in section 18. 'Assignment of Arrays' in the 2008 document 'An Oberon Compiler for the ARM Processor' which the Astrobe Oberon compiler originated from. "In contrast to original Oberon, where a (the) standard procedure COPY is used, the “:=” symbol now also applies to arrays and strings." "The arrays must have the same element type, but the source array may be shorter than the destination array. Hence, the length (count) is taken from the source. The length comparison is performed by the compiler. This is not possible in the case of open arrays, when the check must be performed at run-time. (Currently, only the source may be an open array)." https://www.inf.ethz.ch/personal/wirth/Oberon/Oberon.ARM.Compiler.pdf However, dynamic array variables were also implemented in that compiler. As they are not included in Oberon-07, the structural equivalence of arrays used in assignments is a less useful feature. Regards, Chris Burrows CFB Software http://www.astrobe.com
participants (8)
-
Andreas Pirklbauer -
August Karlstrom -
Chris Burrows -
Diego Sardina -
Dieter -
Felix Friedrich -
Jörg -
Luca Boasso