Outer / Inner access in inherited classes - a question

258 views
Skip to first unread message

Milan Zimmermann

unread,
Oct 19, 2014, 5:44:06 PM10/19/14
to newspeak...@googlegroups.com
  Hi:

  I use the Linux version of Newspeak from http://www.newspeaklanguage.org/downloads - the Sep 14,2013 version, and following examples of nested classes from the specs in http://bracha.org/newspeak-spec.pdf - April 13, 2014 version.

  There is a problem that I am surprised with. I am describing a simplified version of an issue I get when following the Outer/ChildOfOuter/GrandChildOfOuter example in the specs.

  I am sure this is a result of some deep misunderstanding on my end (but giving a very small chance something in the specs has evolved since the version of Newspeak I use)
 
  Defining:

  class Outer = () (
    public class Inner = ()()
  )
  
  and:

  class ChildOfOuter = Outer ()()

  Then evaluating in workspace:

    Outer new Inner. => Outer`Inner`949

    ChildOfOuter new Inner. => MessageNotUnderstood: ChildOfOuter>>Inner

  Should I not be surprised by the MessageNotUnderstood? I thought the child class ChildOfOuter would have access to the Inner in it's parent but it seems otherwise.

  Sorry if this is obvious

  Thanks
  Milan

Gilad Bracha

unread,
Oct 19, 2014, 6:37:05 PM10/19/14
to newspeak...@googlegroups.com
Hi Milan,

Where is ChildOfOuter declared? Your message leaves the impression that it is a top level class.  If this is the case, you cannot subclass another class, because the Newspeak language has no top level namespace. We should give an error in this situation, but we don't; that's a bug on our part. 

So what happens in practice is that ChildOfOuter is a subclass of Object. You can verify this by inspecting ChildOfOuter and seeing what the superclass slot's value is. I expect you'll see KernelForSqueak`Object.

Consequently, ChildOfOuter does not understand Inner. If it was a subclass of Outer, it would work as you expected.

I apologize for the bug and the confusion it causes.
--
Cheers, Gilad

Milan Zimmermann

unread,
Oct 21, 2014, 12:36:53 AM10/21/14
to newspeak...@googlegroups.com
Hi Gilad,

Thanks very much for your answer and sorry it took me a while. 

Yes, as you said, both Outer and ChildOfOuter were declared as top level classes (which I could see both in the browser and also evaluating ChildOfOuter and inspecting the result - the superclass showing Kernel`Object`.

The error is completely on my end, I did not realize, reading the specs examples where inheritance is used (and other examples I can find), that one has to always create a top level class / module for them (well that is, if that is a correct understanding).

So in my simple example, when I create this hierarchy instead (added My to class names so my instances do not get confused for reading)

    class MyContext = ()(
      class MyOuter = () (
        public class MyInner = ()()
      )
      class MyChildOfOuter = MyOuter ()()
    )

Then in workspace

    MyContext new MyOuter new MyInner             => MyContext`MyOuter`MyInner`3716
    MyContext new MyChildOfOuter new MyInner => MyContext`MyOuter`MyInner`954

Which works as expected, except I am slightly surprised by the result representation of the instance. What I mean is, instead of  MyContext`MyOuter`MyInner`954, I would expect it to be MyContext`MyChildOfOuter`MyInner`954. But I think to understand why it is not that way I need to finish reading the specs and the modules paper properly.

Thanks,
Milan
 
For completeness 

    drilling in the 3716 object:
        self             MyContext`MyOuter`MyInner`3716
        enclosingObject  MyContext`MyOuter`3363#3716

    drilling in the 954 object: 
       self             MyContext`MyOuter`MyInner`954
       enclosingObject  MyContext`MyChildOfOuter`461#954

Gilad Bracha

unread,
Oct 21, 2014, 9:33:10 AM10/21/14
to newspeak...@googlegroups.com
Hi Milan,

Your results are exactly what one would expect. The name is based on the lexical scope, not the inheritance hierarchy. Put another way, it is based on the name of the mixin and a number unique to the mixin application.

As you show, the super class of MyContext`MyOuter`MyInner`954 is a MyChildOfOuter.  What's important is that each enclosing class has its own distinct set of nested classes.
--
Cheers, Gilad

Milan Zimmermann

unread,
Oct 21, 2014, 1:19:26 PM10/21/14
to newspeak...@googlegroups.com
Thanks Gilad.

(I understand the uniqueness of nested instances, if what you meant is: MyContext new MyChildOfOuter new MyInner == MyContext new MyChildOfOuter new MyInner => false)

As I wanted to try something extremely simple with Newspeak mixins, maybe a follow up question, is there a reasoning behind the object string representation is chosen to follow the mixin name rather than the inheritance chain? But I should not prolong this thread.

Thanks for your help,
Milan

Gilad Bracha

unread,
Oct 21, 2014, 2:07:11 PM10/21/14
to newspeak...@googlegroups.com
For the most part, the naming convention is an artifact of early implementations. That said, it makes at least as much sense as anything else.  Incorporating the inheritance hierarchy gets unwieldy very quickly for example.
--
Cheers, Gilad

Milan Zimmermann

unread,
Oct 21, 2014, 4:27:16 PM10/21/14
to newspeak...@googlegroups.com
Thanks!
Reply all
Reply to author
Forward
0 new messages