Help - Language - Squeak Semi-formally - 3.7

Previous - Squeak Semi-formally - Next

3.7. Terms 5: Logical Variables

The parts in the previous section are concerned with processing by Squeak and are constants. This section treats variables, and it should  first be noted that in Squeak variables are rather special and different from other languages.

In Squeak, variables are as it were named slots used for arbitrary storage. That is, for Squeak a variable is processed as made up of a string which is a Squeak identifier, and a contents, which has been assigned by Squeak or the user. These pairs of a name and the  contents it refers to is called "variable" because the contents can be changed, while the name remains the same. 

Here there are two points of importance: Squeak initializes anything it recognizes as a variable as nil, until this is undone. (So all variables refer to some contents, if only nil.)

Second, and most important for Squeak: The contents of a variable are anything that can be represented by a well-formed Squeak-expression. This gives Squeak very great power, and it also liberates the user of having to add type-declarations for variables, as is usual in other computing languages, where there are variables but normally of a specific kind, that needs explicit declaration, like "integer", "float" or "string".

So the expressions for v ariables that follows are in fact handles for storage-spaces for the user of Squeak. They come in several kinds, depending on the purpose they serve in Squeak:

variable_name = identifier.

This concerns the names for storing the contents of the "variable" of that name, by assignment (see below). By convention variable names begin with lowercase, but this is not enforced by the system, though it may ask when one uses an initial uppercase whether the variable is to be stored as Global, i.e. accessible to the whole system, and not just by the part in which it is declared

temporaries = "|" [variable_name]* "|".

Temporaries are variables that are only accessible and maintained by Squeak when processing the code in which they occur. They are declared by the user by means of writing them between two bars, separated by whitespace. (Like before, variables are initialized to nil when declared: As soon as you've written "| blab blub |" in a Workspace Squeak has somewhere stored "blab" and "blub" pointing to nil as long as nothing else is assigned to them.

class_name = capital_identifier.

In fact Squeak's classes are Squeak's programs, and one must refer to these by identifiers starting with an uppercase letter. (Note new class_names are usually declared and added in  a browser.)

There are several types of variables, all named by identifiers I list here without explications:

class_variable_name = capital_identifier.
instance_variable_name = identifier.
class_instance_variable_name = identifier.

By convention both instance variables and class instance variables begin with lowercase, but this is not enforced by the system.

Sofar, we have dealt with names for the programs in Squeak, and now we turn to parts  of programs of Squeak: 

argument_name = identifier.

This seems somewhat of a misnomer, since it refers to the names of methods (see below: What are called "methods" in Squeak are in fact Squeak's programs, that are collected in classes, where a class is a collection of programs for a specific purpose).

There is a somewhat important NOTE: argument_names cannot be assigned to (at least it should be disallowed). By convention argument names begin with lowercase, but this is not enforced by the system (though the parser may complain when beginning with upper case). Thus, an argument_name in Squeak is not "an object", because nothing can  be assigned to it.

Now the general approach of Squeak towards getting things done is to have written or gotten somehow a class of behaviors, named by methods, which may be executed by naming the class and  the method and sending both to Squeak. 

The class has an identifier, and the method an argument_name and possibly some parameters. In Squeak, there are three basic kinds of messages: Those with no parameters, those with one parameter, and those with more than one parameter. These are distinguished by the following terms:

unary_selector = identifier.

By convention unary message names begin with lowercase, but this is not enforced by the system. A simple instance is: "2 sin" that when send to Squeak will be calculated as the sinus of the number 2. Here "2" is a name of the class (the nymber 2 in this case) while "sin" is the name of a unary_selector.

There are quite a few unary_selectors in Squeak, for quite a few different purposes. It is a bit different with the next kind of message:

binary_selector = (special_character [special_character]) | ("-" [special_character]) | "|".

The difference is that binary_selectors are mostly used in mathematical contexts, and are mostly the standard mathematical arithmetical terms like +, -, * etc.

Here it should be remarked once more (without explanation) that in Squeak numbers are represented in a somewhat different way than in other programming languages. (This needs some getting used to, but Squeak is remarkably powerful with numbers as well.)

keyword = identifier ":".

This is used to define key_word messages (below), that correspond mostly to the methods with more than one parameter - of which there are very many in Squeak. By convention keywords begin with lowercase, but this is not enforced by the system.

Previous - Squeak Semi-formally - Next