Smalltalk inconsistencies

I am new to Smalltalk and found out about it at Squeak. But I find many things confusing in Smalltalk. In Squeak, MetaClass and MetaClass class are mutually related. If I want to create a MetaClass object, I have to send a new message to its class, which is equal to the MetaClass class . But he must have already existed as an object to receive the message. Therefore, I must first create a MetaClass class object that can only be executed by sending a new message to a MetaClass object that has not yet been created. So this is a problem with a chicken or an egg.

Of course, now I can create objects in Squeak, because the MetaClass and MetaClass class objects MetaClass already created automatically when Squeak is open. But I do not know how to do this. They may have been created in some way by sending messages. But then this contradicts the spirit of Smalltalk: everything happens by sending messages, with the exception of a few points (declaration of variables, assignments, returns and primitives).

Is there something wrong with the above reasoning? Thanks in advance.

+6
source share
3 answers

The "automatically created" process is actually called bootstrapping . This solves the problems with the chicken and the egg. Once the system boots up, everything else can be expressed in terms of the system itself. Thus, there is no contradiction with the Smalltalk philosophy that everything happens when sending messages, because it only becomes a Smalltalk system after it starts up.

+11
source

Your question is twofold, answer it separately.

How are mutually dependent classes created?

You are right, the Metaclass and Metaclass class are a feature of the parallel hierarchy of Smalltalk classes and metaclasses. How are they created?

It depends on the Smalltalk used. For GNU Smalltalk, I'm not sure, but for descendants of the original Smalltalk-80 (VisualWorks, VA aka VisualAge, SqueakPharo) are created in the Bootstrap process, which creates the original image.

However, at least for Squeak, this bootstrap happened at least 15 years ago, if not more. Metaclass , and its class may be even older than 30 years.

In short, both classes are created outside of typical image processing and are manually related.

But if the objects are years old, this leads to the question

What happens when you start Smalltalks?

Unlike languages ​​like Ruby or Python, which are also object oriented, Smalltalk does not need to create a basic object environment with things like Object every time it starts. Why?

When Smalltalk saves and turns off, it basically takes a snapshot of its entire object and saves this live object to a file. When it starts up again, it just needs to read the objects from the snapshot and β€œanimate” them.

Therefore, for the Metaclass and Metaclass class both objects are read from the snapshot and restored, and from that moment they are fully functional; they no longer need to be created manually.

+12
source

Metaclass class class = Metaclass is a classic academic example of a weird loop. But if you learn a little, you can find many others in Smalltalk.

  • The class superclass is nil, which is an instance of UndefinedObject, which is a subclass of Object (a longer chain through ProtoObject in Squeak Object superclass superclass class superclass = Object )
  • MethodDictionary methods are stored in an instance of MethodDictionary ( MethodDictionary methodDictionary class = MethodDictionary ).
  • The name of the symbol is an instance of Symbol (works with ByteSymbol in Squeak ByteSymbol name class = ByteSymbol ).
  • ArrayedCollection subclasses are stored in an Array instance, which is a subclass of ArrayedCollection ( Array superclass subclasses class = Array ).
  • Smalltalk is a system dictionary that points to Smalltalk using the #Smalltalk key (this is less straightforward in Squeak, (Smalltalk globals at: #Smalltalk) = Smalltalk ).

I will let you continue the list yourself.

Whatever the implementation, the final question is whether you can create a self-describing system such as Smalltalk without these strange loops, and you might not see such a positive answer if you follow the demotion http: // en. wikipedia.org/wiki/Kurt_G%C3%B6del#The_Incompleteness_Theorem

Due to the bootstrap problem encountered with such a system, cloning yourself to change yourself is an effective way, and this is especially true in the Smalltalk image when you want to change the base classes that you use to modify / describe classes.
Hence my previous and short answer, which was deleted by applying the letter of the rules ( https://stackoverflow.com/help/deleted-answers ), more than the spirit in my opinion:

And here is how it was allowed: http://en.wikipedia.org/wiki/Drawing_Hands

In the latter case, I would rather read The Incredible Smalltalk Sequence , but I'm definitely biased.

+8
source

Source: https://habr.com/ru/post/947585/


All Articles