<div dir="ltr">I think Interfaces / Protocols / Dynamic Traits (what Rust calls them) would be a quite useful extension to Oberon. I'm looking at doing it a different way, like this: <div><br><font face="monospace">  VAR W: Texts.Writer;<br></font><div><font face="monospace"><br></font></div><div><font face="monospace">  TYPE <br>       I* = POINTER TO IDesc;<br>       IDesc* = RECORD<br>            h: INTEGER<br>       END ;<br><br>       R* = POINTER TO RDesc;<br>       RDesc* = RECORD<br>            h: REAL<br>       END ;<br><br>       Stringer* = INTERFACE OF<br>            PROCEDURE String* (VAR a: ARRAY OF CHAR) ; <br>       END ;<br><br><br>  PROCEDURE ( i : I ) String* (VAR a: ARRAY OF CHAR) ;<br>  BEGIN a := "integer"<br>  END String;<br><br>  PROCEDURE ( r : R ) String* (VAR a: ARRAY OF CHAR) ;<br>  BEGIN a := "real"<br>  END String;<br></font><br></div><div>In the above scheme an Interface looks just like a collection of type-bound procedure definitions with no bodies.</div><div><br></div><div>The trick is when it comes time to use the interface, which is when the code needs to know which actual procedure to call based on the record type assigned to it during execution. The record type assigned to an interface could be any record that contains the String type-bound procedure (in this case.) It might be the first method, or the third, or the sixth... Go solves this by generating a dispatch table for the Interface when a type is assigned to it. </div><div><br></div><div>In Oberon that table-making routine could be satisfied by adding another Trap condition in Kernel.Trap much like how New is implemented.</div><div><br></div><div><font face="monospace">  PROCEDURE Test*;<br>      VAR i: I; r: R; t: ARRAY 32 OF CHAR; <br>        s,s2: Stringer; <br>        x0, x1, u: REAL;<br>        <br>  BEGIN <br></font><span style="font-family:monospace">      NEW(i); NEW(r);</span><font face="monospace"><br></font></div><div><font face="monospace">      i.h := 3;<br>      r.h := 7.5;<br>      s := i;</font></div><div><font face="monospace">      s.Stringer(t); </font></div><div><font face="monospace">      Texts.WriteString(W,t);<br>      s := r;</font></div><div><font face="monospace">      s.Stringer(t);<br>      Texts.WriteString(W,s);</font></div><div><font face="monospace">   END Test;<br></font><br>The above idea for Interfaces builds on the mechanisms already in place in the Oberon-2 compiler and run-time. I think it would be quite useful for allowing a program to choose from multiple implementations of an interface without constraining them to derive from the same base type while still keeping strong static typing and separate linking and loading.</div></div><div><br></div><div>Chuck</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 25, 2020 at 6:27 AM Luca Boasso <<a href="mailto:luke.boasso@gmail.com" target="_blank">luke.boasso@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div>A key feature of protocols / interfaces is the safe multiple inheritance: you can explicitly or implicitly (like in the Go language) implement several interfaces and be type compatible with each one of them.<br></div><div><br></div><div>Do you support something like the following?<br></div><div><span style="font-family:monospace"><br></span></div><div><font size="4"><span style="font-family:monospace">TextDesc = RECORD (TextProtocol.TextDesc, WriteProtocol.WriterDesc) END ;  (*this means: “implements TextProtocol.TextDesc AND WriteProtocol.WriterDesc "*)</span></font></div><div><br></div><div>If this is not supported I don't see this feature being that useful. To support the feature above the implementation is more complicated than Oberon-2's bound procedures. See <a href="https://research.swtch.com/interfaces" target="_blank">https://research.swtch.com/interfaces</a> for one way of doing this, or<a href="http://www.academia.edu/download/42084165/Efficient_Implementation_of_Java_Interfa20160204-28309-28q4h3.pdf" target="_blank"> "Efficient implementation of Java interfaces: Invokeinterface considered harmless" </a><br></div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Sun, Oct 25, 2020 at 6:46 AM Andreas Pirklbauer <<a href="mailto:andreas_pirklbauer@yahoo.com" target="_blank">andreas_pirklbauer@yahoo.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Correction: In Text1, it’s TextDesc = RECORD (TextProtocol.TextDesc) of course<br>
<br>
—————————<br>
<br>
Protocols (sometimes called interfaces) can be added to<br>
Oberon-2 without adding any keywords to the language.<br>
<br>
This is one of the key differences to how it is usually defined<br>
and implemented, e.g. in Swift [*] or in Integrated Oberon [**]<br>
<br>
Under the new minimalistic design, what distinguishes a protocol<br>
from an actual implementation (of the class) is that in the protocol<br>
definition the implementations of the class methods are simply not<br>
defined. Instead, any module that *imports* a protocol definition<br>
can “adopt” (i.e. implement) it. See the example below.<br>
<br>
An experimental implementation showed that if the language<br>
is extended in *this* way, the implementation cost is minimal.<br>
<br>
But the question is: Is it worth it? Simplicity of implementation<br>
should of course not be a criteria for adopting a new feature.<br>
<br>
Personally, I am rather sceptical of the usefulness of protocols.<br>
But perhaps someone provides a good reason to adopt them.<br>
<br>
-ap<br>
<br>
<br>
Example:<br>
<br>
  MODULE TextProtocol;  (*protocol definition*)<br>
    TYPE Text = POINTER TO TextDesc;<br>
      TextDesc = RECORD data*: (*text data*) END ;<br>
      PROCEDURE (t: Text) Insert (string: ARRAY OF CHAR; pos: LONGINT);<br>
      PROCEDURE (t: Text) Delete (from, to: LONGINT);<br>
      PROCEDURE (t: Text) Length (): LONGINT;<br>
  END TextProtocol;<br>
<br>
  MODULE Text1; (*one implementation of the Text protocol*)<br>
    IMPORT TextProtocol;<br>
    TYPE Text = POINTER TO TextDesc;<br>
      TextDesc = RECORD (TextProtocol.TextDesc) END ;  (*this means: “implements TextProtocol.TextDesc"*)<br>
<br>
    PROCEDURE (t: Text) Insert (string: ARRAY OF CHAR; pos: LONGINT);<br>
    BEGIN (*implementation of Insert*)<br>
    END Insert;<br>
<br>
    PROCEDURE (t: Text) Delete (from, to: LONGINT);<br>
    BEGIN (*implementation of Delete*)<br>
    END Delete;<br>
<br>
    PROCEDURE (t: Text) Length (): LONGINT;<br>
    BEGIN (*implementation of Length*)<br>
    END Insert;<br>
  END Text1;<br>
<br>
<br>
  MODULE Text2; (*another implementation of the Text protocol*)<br>
    IMPORT TextProtocol;<br>
    TYPE Text = POINTER TO TextDesc;<br>
      TextDesc = RECORD (TextProtocol.TextDesc) END ;  (*this means: “implements TextProtocol.TextDesc"*)<br>
<br>
    PROCEDURE (t: Text) Insert (string: ARRAY OF CHAR; pos: LONGINT);<br>
    BEGIN (*implementation of Insert*)<br>
    END Insert;<br>
<br>
    PROCEDURE (t: Text) Delete (from, to: LONGINT);<br>
    BEGIN (*implementation of Delete*)<br>
    END Delete;<br>
<br>
    PROCEDURE (t: Text) Length (): LONGINT;<br>
    BEGIN (*implementation of Length*)<br>
    END Insert;<br>
  END Text2;<br>
<br>
<br>
[*] <a href="https://docs.swift.org/swift-book/LanguageGuide/Protocols.html#" rel="noreferrer" target="_blank">https://docs.swift.org/swift-book/LanguageGuide/Protocols.html#</a><br>
[**] <a href="https://github.com/io-core/technotes/blob/main/technote014.md" rel="noreferrer" target="_blank">https://github.com/io-core/technotes/blob/main/technote014.md</a><br>
<br>
--<br>
<a href="mailto:Oberon@lists.inf.ethz.ch" target="_blank">Oberon@lists.inf.ethz.ch</a> mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/mailman/listinfo/oberon</a><br>
</blockquote></div>
--<br>
<a href="mailto:Oberon@lists.inf.ethz.ch" target="_blank">Oberon@lists.inf.ethz.ch</a> mailing list for ETH Oberon and related systems<br>
<a href="https://lists.inf.ethz.ch/mailman/listinfo/oberon" rel="noreferrer" target="_blank">https://lists.inf.ethz.ch/mailman/listinfo/oberon</a><br>
</blockquote></div>