This is the basic structure of a script:
scriptName " a comment " | temporary variables | statements
All names in scripts are case-sensitive. Script names should begin with a lowercase letter because that is the convention that most Smalltalk programmers follow. Names can be any length and should be as descriptive as possible. Names are often made up of several words written together. By convention, the initial letter of each word, except the first word, is capitalized. This improves readability. The names of variables also follow this convention. Here are some examples:
subtractDays calculateOvertimePay currentRow aString
Comments are enclosed in double quotation marks (" ") and can be placed anywhere in a script. Scripts usually begin with a comment that describes what the script does just after the selector name.
To display the results of any of the code fragments in this section, simply type it into the System Transcript, select all of the text you typed, and then select Display from the System Transcript's pop-up menu. This runs the selected code and displays the resulting object.
With VisualAge scripts, unlike many traditional languages, you do not have to worry about data types when you declare variables. Temporary variables are declared simply by listing their names inside vertical bars (|) near the beginning of a script, before any statements. When the script ends, temporary variables are lost.
In the following example, aNumber and aString are temporary variables:
doSomething | aNumber aString | aNumber := 5 * 10. aString := 'abc'.
The statements in a script are simply a series of message expressions. Message expressions can also include assignment statements, because messages always answer a result object.
Separate the statements of a script with a period (.).
To end a script and return its answer, use a caret (^) at the beginning of a message expression. If you do not explicitly return an answer, the receiver of the message is returned instead.
The following script takes two arguments, rate and hours, and returns pay.
calculatePay: rate hours: hours | pay | pay := hours * rate. ^pay
The following words have special meaning: