[NTLK] NewtonScript Inheritance Question

J Caffiney caffiney at gmail.com
Thu Oct 13 13:24:03 PDT 2022


While tinkering the other day, I came across NewtonScript behavior that
puzzled me. I'd appreciate any light anyone can shine on the issue. Details
follow.

I've attached some PNG illustrations taken from pages 97 to 99 of
"Programming for the Newton Using Windows," by Julie McKeehan and Neil
Rhodes.

The book summarizes inheritance for slot access with the table shown in
"Inheritance Table.png". It specifically makes the point that "...frame.
syntax (for example, foo.slotA ) does not use parent inheritance."

The book illustrates the state of a set of objects both before and after
sending a message one:SillyMethod(). The attached files "Before.png" and
"After.png" show these states.

I typed out the example and executed it using the Einstein Toolkit. I added
a number of Print statements to display the values of a through g both
before and after the message send:

//
> // Inheritance Demo
> //
> kAppName := "IDemo:JTK";
> kAppSymbol := '|IDemo:JTK|;
> kAppLabel := "IDemo";
>
> seven := {
>    g: "x",
> };
>
> six := {
>    f: "x",
>    _proto: seven,
> };
>
> five := {
>    e: "x",
>    _proto: six,
> };
>
> four := {
>    d: "x",
> };
>
> three := {
>    c: "x",
>    _proto: four,
>    _parent: five
> };
>
> two := {
>    b: "x",
>
  SillyMethod: func()
>       begin
>          Print("\n");
>          Print("------ Section 2 ------\n");

         Print("a: "); Print(a); Print("\n");
>          Print("b: "); Print(b); Print("\n");
>          Print("c: "); Print(c); Print("\n");
>          Print("d: "); Print(d); Print("\n");
>          Print("e: "); Print(e); Print("\n");
>          Print("f: "); Print(f); Print("\n");
>          Print("g: "); Print(g); Print("\n");
>
>           a := "apple";
>           b := "boat";
>           c := "cat";
>           d := "dog";
>           e := "elephant";
>           f := "fox";
>           g := "gazelle";
>
>           Print("------ Section 3 ------\n");
>
>           Print("\n");
>
          Print("a: "); Print(a); Print("\n");
>
          Print("b: "); Print(b); Print("\n");
>           Print("c: "); Print(c); Print("\n");
>
          Print("d: "); Print(d); Print("\n");
>           Print("e: "); Print(e); Print("\n");
>
          Print("f: "); Print(f); Print("\n");
>           Print("g: "); Print(g); Print("\n");
>
      end,

};
>
> one := {
>    a: "x",
>    _proto: two,
>    _parent: three,
> };
>
> Print("\n");
> Print("------ Section 1 ------\n");
>
> Print("one.a: "); Print(one.a); Print("\n");
> Print("one.b: "); Print(one.b); Print("\n");
> Print("one.c: "); Print(one.c); Print("\n");
> Print("one.d: "); Print(one.d); Print("\n");
> Print("one.e: "); Print(one.e); Print("\n");
> Print("one.f: "); Print(one.f); Print("\n");
> Print("one.g: "); Print(one.g); Print("\n");
>
> one:SillyMethod();
>
> Print("\n");
> Print("------ Section 4 ------\n");
>
> Print("one.a: "); Print(one.a); Print("\n");
> Print("one.b: "); Print(one.b); Print("\n");
> Print("one.c: "); Print(one.c); Print("\n");
> Print("one.d: "); Print(one.d); Print("\n");
> Print("one.e: "); Print(one.e); Print("\n");
> Print("one.f: "); Print(one.f); Print("\n");
> Print("one.g: "); Print(one.g); Print("\n");
>
> Print("\n");
>

The output of its execution is listed below. Sections 1, 2, and 3 match my
understanding of NewtonScript inheritance, but shouldn't Section 4 fail to
return values for slots c through g? The code is using frame.slot syntax
for the objects it is printing in Section 4, but it seems to be following
both the _proto and the _parent chains. Shouldn't it only follow the _proto
chain?

Compiling inline...
>
> ------ Section 1 ------
> one.a: x
> one.b: x
> one.c: x
> one.d: x
> one.e: x
> one.f: x
> one.g: x
>
> ------ Section 2 ------
> a: x
> b: x
> c: x
> d: x
> e: x
> f: x
> g: x
> ------ Section 3 ------
>
> a: apple
> b: boat
> c: cat
> d: dog
> e: elephant
> f: fox
> g: gazelle
>
> ------ Section 4 ------
> one.a: apple
> one.b: boat
> one.c: cat
> one.d: dog
> one.e: elephant
> one.f: fox
> one.g: gazelle
>
> Info: package compiled.


 Can anyone tell me what I'm missing?


 Inheritance Table.png
<https://drive.google.com/file/d/1OY010hHTb3tMn_sqcaJ0O62g4lE_aPWo/view?usp=drive_web>

 Before.png
<https://drive.google.com/file/d/17nUANGv7-6SQyYoT3M-0TY9PpSw2fH5y/view?usp=drive_web>

 After.png
<https://drive.google.com/file/d/1pxznLJsZKYHFyKDeCiqW3uTlNvPlR_J-/view?usp=drive_web>


More information about the NewtonTalk mailing list