Skip to content

How to Program in Self

Valery Ushakov edited this page Aug 19, 2023 · 14 revisions

This version of 'How to Program in Self' is taken from the Self Handbook at http://handbook.selflanguage.org/4.5/howtoprg.html It references the original images, but has some small changes.

Introduction

The Self programming environment provides facilities for writing programs, and the transporter provides a way to save them as source files. Of all the parts of Self, the programming environment probably has the least research ambition in it. We simply needed to concentrate the innovation in other areas: language design, compiler technology, user interface. The Self programming environment strives to meet the high standard set by Smalltalk’s, but with a more concrete feels. The transporter, on the other hand, is somewhere in-between completely innovative research and dull development. It attempts to pull off a novel feat—programming live objects instead of text—and partially succeeds. Its novelty lies in its view of programs as collections of slots, not objects or classes, and its extraction of the programmer’s intentions from a web of live objects.

Since Self 4.0, the environment has evolved a little—mostly in the form of new affordances. On the Macintosh, Self 4.5 uses ctrl-click for a middle-mouse click, and uses command- (the apple key) click for the right button click. So wherever the text says “left-button-click” just click with the mouse, where it says “middle-button click” hold down the ctrl key and click with the mouse, and where it says “right button click” hold down the command key and click with the mouse. I use a Kensington Turbo Mouse with the buttons mapped appropriately. These mappings are defined in Self, so you can change them by editing the whichButton: method in the initialization category in traits ui2MacEvent.

Browsing Concepts

Introducing the Outliner

Objects in the Self 4.5 environment are represented as outliners, which can expand to show increasing levels of detail. One of these objects has been designed to provide a convenient context for typed-in commands, and so it is called the shell. If the shell is not already present on your screen, you can summon it by pressing the middle mouse button on the background and selecting shell.

shell

In Self 4.5, outliners now sport three small buttons in the top-right-hand corner labeled “/\”, “E”, and “X”. These buttons summon the object’s parents, add an evaluator text region to the bottom of the outliner, and dismiss the outliner. Press the “E” button to get an evaluator. Type anExampleObject into the evaluator (it will already be selected) and hit the Get it button (or type metareturn on UNIX, or command-return on MacOS X):

Get It

in case you are using an image that doesn't include it.

  1. save a copy of https://github.com/russellallen/self/blob/master/objects/misc/programmingExamples.self
  2. type into the shell '/download/path/here/programmingExamples.self' runScript
  3. press Do it

The result object appears in your “hand” raised above the screen as if you were dragging it with the left button. Just click the button to set it down.

anExampleObject

As with most other things on the Self screen, the left button picks it up and moves it. (For buttons and other things that use left-button for other purposes, you can grab them with marquee selection (really the carpet morph in Self) or with the “Grab” item on the right-button menu.)

Expand and Collapse

Left-click on the triangle [1] to expand the object and see more information:

anExampleObject

Now it shows a summary of modules containing the slots in this object (just programmingExamples here), four slots, and a category containing more slots, although those slots are not shown yet.

Categories

Clicking the top triangle now would collapse this object outliner, but instead look inside the category by clicking its triangle:

anExampleObject

And, one more click expands the subcategory:

anExampleObject

Slots

The little icons on the right edges of the slots reveal the type of slot: methodslot for a method slot (a slot containing a method), constantslot for a constant slot (a slot containing a data object), and assignableslot for an assignable slot (a pair of slots containing a data object and the assignment primitive). In order to save space, the data slot and its corresponding assignment slot are lumped together. (In other words in addition to the visible slot named aCategorizedVariable containing 17, there is another, invisible slot named aCategorizedVariable: containing the assignment primitive.)

To look at the object contained in a data (constant or assignable) slot, just click on its icon. But if the slot is a method, clicking its icon opens up a text editor on its source. For example, clicking on the icon at the right of the whoAmI box opens a text editor displaying its source (and typing control- L widens the object to show all the text in the selected window):

anExampleObject

Text Editors

The background of the editor is lighter than the outliner as a whole, and this difference indicates that this editor is the current typing focus: no matter where the mouse is you can type into this editor. A left-click on another editor will select that one as the typing focus, and to indicate that it is no longer the focus, this editor’s background will change to match the outliner:

anExampleObject

The white triangle in the lower-right corner of the editor (which can barely be seen in the printout of this document) can be dragged to resize the editor.

Someone has done a poor job of indenting this method, so fix it by clicking to the left of the capital– I and deleting two spaces:

anExampleObject

The red and green buttons that just appeared indicate the text has been changed; it no longer reflects the source code of the real method. Hitting the red button will cancel the changes, while hitting the green button will accept them and change the method:

anExampleObject

Self text editors will honor the cursor arrow keys, the copy, paste, and cut Sun keys, and many emacs-style control characters:

Clone this wiki locally