-
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.
- Introduction
Since Self 4.0, the environment has evolved a little—mostly in the form of new affordances. On the Macintosh, Self 4.1 uses option-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 option 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

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. > >1. save a copy of https://github.com/russellallen/self/blob/master/objects/misc/programmingExamples.self >1. type into the shell `'/download/path/here/programmingExamples.self' runScript` >1. 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.)
- Expand and Collapse

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
 And, one more click expands the subcategory:

- Slots
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):

- Text Editors
 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: