TWENEX's BASIC programming system is LOTS BASIC, developed at Stanford University.
Start BASIC with the EXEC command BASIC
. Return to EXEC with the BASIC command MONITOR
.
The following tutorial is adapted from chapter 17. “Using BASIC” in LOTS DECSYSTEM-20 Overview Manual1). (The referenced chapter contains additional information on LOTS BASIC file manipulation and other commands.)
(Although not strictly relevant to LOTS BASIC, a description of the BASIC programming language largely the same as that supported by LOTS BASIC can be found in DECsystem-10 BASIC Conversational Language Manual2).)
For those already familiar with BASIC and who would like a summary of LOTS BASIC commands, skip the following example and see BASIC Command Summary.
Here is an example of how you might start BASIC, enter a program and run it, then leave BASIC. In the example, what the user types in is underlined. We start in the EXEC, which prompts with the @. The BASIC command starts the BASIC program.
@basic
Welcome to LOTS-BASIC
For help, type HELP
To exit, type MONITOR
BASIC types a greeting message, spaces down a line and stops. We may no begin typing in our program, including the line numbers. At the end of each line we press the RETURN key; BASIC will then be ready to accept another line or a command.
10 print “Type in a number”
20 input a
30 if a=0 go to 70
40 let s2=a*a
50 print “The square of”,a,“is”,s2
60 go to 10
70 stop
We have finished typing in the program, so we ask BASIC to run it by typing the RUN command. BASIC knows this command is not part of the program because it does not begin with a line number. BASIC types out the name of the program and the date and time. The heading “NONAME” stems for the fact that we haven't named the program yet.
run
NONAME 17:00 10-Aug-84
? NO END INSTRUCTION
TIME: 0.04 SECS.
READY
BASIC tells us that the program needs an END statement, then it tells us how long the run took. When BASIC types READY, it means that it is waiting for another command or a new program line. We need to add an END statement, which is always the last line in a program. We can give it any number greater than 70. The line numbers aren't required to be incremented by tens.
100 end
Now our program should run, so we try it again. The “?” tells us that we should type something in. We type in a 15 and BASIC tells us the square of it.
run
NONAME 17:01 10-Aug-84
Type in a number
? 15
The square of 15 is 225
Type in a number
? 666
The square of 666 is 443556
Type in a number
? 0
TIME: 0.24 SECS.
READY
By the way, you probably understood the program as it was written, without any commentary on our part; this illustrates the advantage of BASIC: it is easy to understand. Now let's add one more line.
55 print “And that's the truth!”
It makes perfect sense to insert this line between lines 50 and 60, and this is what BASIC does. Let's see what the program looks like now. The “NH” we append to the “LIST” stands for “no header”.
listnh
10 PRINT “Type in a number”
20 INPUT A
30 IF A=0 GO TO 70
40 LET S2=A*A
50 PRINT “The square of”,A,“is”,S2
55 PRINT “And that's the truth!”
60 GO TO 10
70 STOP
100 END
READY
We rerun the program to see the effect of the new line.
runnh
Type in a number
? 4
The square of 4 is 16
And that's the truth!
Type in a number
? 0
TIME: 0.19 SECS.
READY
Having put so much effort into our program, we would like to keep it around for later use. In saving it, we decide to give it the name TEST.
save test
READY
In the future, when we are in BASIC and want to retrieve this program, we would use the command “OLD TEST”. We have reached the end of our example, se we return to the EXEC.
monitor
@
We will find our saved program on our disk area under the name TEST.BAS.
This is a summary of commands in version 17D of LOTS BASIC.
CTRL/C | Interrupts the currently executing program and returns to BASIC command level. To return to the EXEC, give the MON command. |
BYE | Logs you completely off the system. |
CATALOG dev: | Lists onto the user's terminal the names of the user's files which exist on the specified device. |
COPY dev:filenm.typ > dev:filenm.typ | |
Copies the first file onto the second. | |
DELETE line number arguments | |
Erases the specified lines from core. For example, “DELETE 11,44-212,13” erases line 11, lines 44 through 212, and line 13. If no arguments are specified, an error message is returned. It is not necessary to use the delete command to erase lines. You can erase a line simply by typing its line number and then depressing the return key. | |
LIST line number arguments | |
Lists the specified lines of the program currently in core onto the user's terminal. The line number arguments are of the form described under the delete command. If no arguments are specified, the entire program is listed. | |
MONITOR | Returns to the EXEC. BASIC may be resumed via CONTINUE. This is just like CTRL/C for most non-BASIC programs. BASIC intercepts CTRL/C aside from returning to BASIC command level. |
NEW dev:filenm.typ | |
The program currently in core is erased from core and the specified filename is established as the name of the “program currently in core”. N.B., at the end of execution of this command, no lines exist in core. | |
OLD dev:filenm.typ | |
The program currentloy in core is erased from core and the specified file is pulled into core to become the new “program currently in core”. | |
RENAME dev:filenm.typ | |
Changes the name of the program currently in core to the specified name. | |
REPLACE | See SAVE. |
RESEQUENCE | Changes the line numbers of the program currently in core to 10, 20, 30,…. (Line numbers within lines (as, GO TO 1000) are changed appropriately). |
RUN | Compiles and executes the program currently in core. The command RUNNH is equivalent, but runs the program without printing a header. |
SAVE dev:filenm.typ | |
Writes out the program currently in core as a file with the specified name. BASIC will return an error message if save attempts to write over an existing file; to write over a file you must type “REPLACE” instead of “SAVE”. | |
SCRATCH | Erased from core the program currently in core. |
SYSTEM | Exits from BASIC to monitor level. N.B., the contents of core are lost. You must give the EXEC command REENTER rathre than CONTINUE, START, or BASIC to resume the current BASIC program. “MONITOR” is recommended instead of “SYSTEM”. |
UNSAVE dev:filenm.typ | |
Deletes the specified file. More than one file can be specified; for example, UNSAVE DSK:ONE.FOR,SX:TEST.BAS |
In the commands above which accept such arguments, if “dev:” is omitted, “DSK:” is assumed; if “.typ” is omitted, “.BAS” is assumed. A null file type is indicated by “.” with no “typ”. The SAVE, REPLACE, and UNSAVE commands allow the “filenm” part of the argument to be omitted, in which case “.typ” must be omitted also and the name and file type of the program currently in core are assumed.
The keywords of commands (CATALOG, LIST, etc.) may be abbreviated to their first three letters. Only the three letter abbreviation and the full word form are legal; intermediate abbreviations such as CATAL, for example, are not allowed. If an intermediate abbreviation is used, the extra letters will be seen as part of the command argument (because BASIC does not see blank spaces or tabs at command level.) For example, “CATAL SX:” would be seen as a request to catalog the device “ALSX:”. An example of a legal abbreviated command is: CAT DOC:
Whenever BASIC finishes executing a command, it types “READY”. It does not answer “READY” after deleting a line by the alternate method described under the delete command or after receiving a line for the program currently in core from the user's terminal.
To insert or replace a line in the program currently in core, simply type the line and then press the RETURN key. BASIC distinguishes between lines (which must be stored or erased) and commands (which must be processed) by the fact that a line always begins with a line number whereas commands all begin with letters.