|
Welcome to the Squeak pages of Maarten Maartensz. See: Map + Tour + Tips + Notes + News + Home |
|
|
|
Using Workspaces and Transcripts Workspaces in Squeak can be used for three main purposes, of which the last two are related · Editing · Valueing · Transcripts First, one can use a Workspace as an editor of textfiles, and as such there are quite a few commands one can use, most of which are peculiar to Smalltalk and Squeak. More of this below and by way of the link: Editing. Second, inside a Workspace one can write Expressions in the Squeak Language SL and value these. This can happen in three basic ways: One selects the Expression by highlighting it and does Alt-p for printit and Alt-i for inspect it. In any case the Expression is valued by Squeak and the result is displayed inside the Workspace immediately after the highlighted Expression or the value is displayed in an Inspector window. More of this below and by way of the link: Valueing. Third, one can do the same and send the result to a Transcript window. More of this below and by way of the link: Transcripts. Valueing and using Transcripts make Workspaces an amazingly valiant editor to do science and much else with, because in fact one can use a considerable amount of Squeak's powers about numbers and strings inside a Workspace or Transcript. There is much more to both Smalltalk and Squeak, but Valueing Expressions in Workspaces or Transcripts itself shows programming in Squeak (or pure Smalltalk 80 in an MVC-project in Squeak). So here we have to start talking about programming in Smalltalk and Squeak also, about which hold opinions not all found in current textbooks. Here are links to three files about Squeak in which I give my own version, derived from those of some others
But let's here start with simple editing in Workspaces. Editing There are many commands in Workspaces that start with Alt (in Windows). One way to see them is to pop up a (World Menu - help - commandkey help). This puts a textwindow on the screend named "Command Key Actions" that lists and describes all possibilities.ValueingValueing is called so basically because SL contains a special constant value which when appended to any valid Expression of Smalltalk evaluates the value of the Expression. It is done in a Workspace by selection a part of the text that forms a valid SL-Expression and do Alt-p or Alt-i on it. Here is a simple example to try. Select the expresion on the next line and do Alt-p. (Simple way: Cursor at end of line - Shift+Home - Alt-p. Alternative: Cursor anywhere in a paragraph and Alt-Space selects it, after which Alt-p prints it if the selected part is a valid Expression
This results in "7". Doing Backspace deletes it if one wants while Alt-z reverses the action very conveniently (and Alt-p then repeats it). Also, you can do Alt-C on the result and then Backspace, with the result that if you place the cursor anywhere else and do Alt-V it prints the result. Even if you don't believe so, if you've tried out the above you've seen and performed a minor miracle - of a rational computable kind. (Leibniz would have been in quiet ecstasy, had he seen this.) In what follows I shall sometimes use "3+4 ==> 7" etc. for: "3+4" when selected with Alt-p prints 7 etc. Of course, the example is "trivial", but the following simple example when valued is not
for Alt-p-ing (let's say) "2 ln" prints the natural logaritm of 2, which you very probably did not know as precisely. This works for lots of basic mathematics. Here are a few examples you're advised to select with Alt-Space and try Alt-p + Alt z on repeatedly
and many more, inckuding the outside Smalltalk rather amazing (and inside too), which again you're advised to select with Alt-Space and try Alt-p + Alt z on repeatedly
This prints the product of 1*2* .... *100. Also, there is this nicety inherited from Smalltalk
Squeak calculates numerical Fractions as fractions, not as reals! I note once more - since I haven't seen this clearly stated anywhere - that the Alt-Space + Alt-p + Alt-z is an excellent way to display input and output alternatively and neatly. Much more is possible, that will be obvious from the following complication of Alt-p: Transcripts A Transcript is an editable Textwindow that also can be saved to which Squeak writes information if it has any that's relevant, e.g. about saving. It is also available to port information to. This is done as follows from a Workspace. Open a Transcript window from the Tools flap and place this Workspace and the Transcript Window so that both are visible. Now select the following line and do alt-d with "d" for "doit" it
The Transcript shows "'Hello ... this is Squeak ". Next, there is the mighty
Incidentally, if you do Select-Alt-p on the above Transcipt instructions what results is not an updated Transcript window but instead " a TranscriptStream". And since I remarked upon it and it IS very useful to SAVE A WORKING IMAGE OFTEN one may as well at this point do (World Menu - save) and see something like
appear in the Transcript window. You can also do a sequence of such commands in one go. Select all of the following three lines and Alt-doit
The last three kines are made up of lines of code in SL together with Comments, that in this case tell the human reader the line number for convenient reference. Squeak when valueing the three lines ignores and in fact skips all comments i.e. all the bits between double quotation marks. Now line 1 above we have used before and can also select independently and select to meanwhile known effect. Line 2 is something new and called a Cascade. This is a series of Expressions of SL separated by ;. In the present case, there are three:
which when Selected+Alt-d result in error-notifications (which you can read and remove with Backspace or Alt-z). Since each line in fact is a fragment of an valid Message and not a Message this is intuitively correct. What the colons ; do in the original (with "line 1" etc.) is assure the resulting values of each of these lines are sent successively to the Transcript window as a Transcriptstream where it is displayed.
|
|
Welcome to the Squeak pages of Maarten Maartensz. See: Map + Tour + Tips + Notes + News + Home |