-
Notifications
You must be signed in to change notification settings - Fork 89
How to Program in Self
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.
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.
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.
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):
in case you are using an image that doesn't include it.
- save a copy of https://github.com/russellallen/self/blob/master/objects/misc/programmingExamples.self
- type into the shell
'/download/path/here/programmingExamples.self' runScript- 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.
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.)
Left-click on the triangle [1] to expand the object and see more information:
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.
Clicking the top triangle now would collapse this object outliner, but instead look inside the category by clicking its triangle:
And, one more click expands the subcategory:
The little icons on the right edges of the slots reveal the type of slot: 


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):
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:
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:
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:
Self text editors will honor the cursor arrow keys, the copy, paste, and cut Sun keys, and many emacs-style control characters:









