The variable of the ST80 can be divided into two major categories: private variables and public variables.
Private variables include two examples of instance variables and temporary variables. Example variables allow all functions (methods) access to the instance, temporary variables are a private variable for a function. An example of a subclass of a class can also access instance variables.
The public variable includes three types of Class variables, global variables, and POOL variables.
The Class variable allows all instances of a class of extreme subclasses to access. Global variables allow all type instances to be accessed. The POOL variable allows an instance of a part of the class to be accessed.
Example variable instance variables are divided into normal variables and index variables.
The normal variable is similar to other languages, and its initialization process is performed when the instance is created, default is NIL (one of five reserved variables), of course, can be explicitly specified.
The way the index variable has different ways to access the normal variable. In fact, the index variable can be simply understood as an array of variable lengths. By: and at: PUT: (actually one of the 32 special functions of ST80) can be accessed. For example: VAR1 AT: 1 Gets the first value of the index variable. VAR1 AT: 2 PUT: 'ABC' Sets the second value of the index variable is a string object 'ABC'.
Why do designers use an index variable such a concept, maybe I should not guess, but I need a reason that I can understand. Since ST80 only supports single inheritance, it is easy to understand, at: and at: PUT: These two functions are defined in the base class Object. If you look at the code of Squeak, it is not difficult to find that the implementation of these two functions is two primitives (Primitive) codes are 60 and 61. In fact, I am very reluctant to see SmallTalk this little secret, because in my heart, she is the perfect and harmonious object-oriented language. But after all, we have had this reality that can't face von Nobiman computers. The ability to encapsulate mechanical language to the right place is the choice. In fact, the implementation of the Array class of ST80 uses an index variable, but this situation has changed in Squeak. Although I can't completely affirm it, I feel that there is no clear index variable in Squeak. Perhaps in ST80, index variables are also implemented as part of an object, in Squeak, has become an independent object. If the fact is just as I mean, I will be very happy to see this, because although it is just a form of change, it feels more harmonious.
There are three kinds of shared variables, although the name is different, essentially can be seen as such something called the pool variable in SmallTalk, but its respective scope is different.
The Class variable and the access method of the pool variable are not different from ordinary variables, but the place where the declaration is different. If you look at the code of Squeak, it is not difficult to find: Instancevariablenames: It is used to declare example variables. Classvariablenames: It is used to declare a Class variable. PoolDictionAries: It is used to declare the pool variable. The global variables are accessed through the special reserved variable name of SmallTalk. It is a hash table. For example: SmallTalk AT: # var1 is used to get the value of the global variable VAR1. SmallTalk AT: # var1 put: 1 is set to 1 for the value of the global variable VAR1. This article is a original article, please indicate the source, reformed the reprint of commercial purposes.