Wang BASIC
Wang BASIC is a series of BASIC programming languages for computers from Wang Laboratories. The term can be used to refer to the BASIC on any Wang machine, but is mostly associated with the versions on the Wang 2200 minicomputer series of the early 1970s. When these machines were updated to the VP series in 1976, BASIC-2 was introduced and remained the pattern for future machines in the 2200 series. A planned BASIC-3 was never released.
Wang offered several models of each version of the 2200 series, differing only in the amount of microcode stored in read-only memory, and thus the number of commands available in BASIC on that machine. For instance, the B model machines differed from the base-model A by doubling the ROM and using that to store a variety of input/output and file management commands.
Wang BASIC closely followed the original Dartmouth BASIC in syntax, but was an interpreter as opposed to a compile-and-go system. A notable feature was that all math used double-precision binary-coded decimal format, which was unusual for BASICs of the era. It lacked many features common to later dialects like Microsoft BASIC, but many of these features were added in BASIC-2.
Description
The following description is based on the original BASIC found in the 2200A. Not all of the instructions listed below would be available in the base model; 2200B and C added dozens of new keywords, and are outlined separately below.Program editing and execution
The original Wang BASIC for the 2200 is a relatively standard version of the Dartmouth BASIC concept, and will be familiar to users of any common BASIC interpreters like Microsoft BASIC. Like most BASIC interpreters, Wang BASIC operated in immediate mode or program mode, switching to the later when a line number is seen at the start of the line when the key is pressed. Line numbers ranged from 0 to 9999. Lines could be up to 192 characters, spanning several on-screen lines, and lines could contain multiple statements separated by colons. To aid organizing large programs, the language included a command.was used to display the program source code, while displayed only the first 15 lines and then paused. When paused, pressing the EXEC key displayed the next 15 lines. saved the current program to cassette and read it back in. would read over the next two files found on the cassette tape, and then stop, allowing a subsequent or to work on the third file. was the opposite of SKIP, rewinding the file pointer. Working with disk storage was slightly more complex, using, where F referred to one of a number of pre-defined drives, in this case "F"ixed.
started execution, and could be directed to a particular line, as in. The command, typically used for debugging, allowed an optional following string that was printed out when that statement was performed. could be used to print out lines as they were run, which was often used in conjunction with the custom and keys on the keyboard to move line-by-line through a program. was used to set a delay between lines in second units; set the delay to zero, would cause it to pause second after each line.
There was no command to clear memory of an existing program, instead one used to reset memory. was the equivalent of NEW but added optional from and to line numbers, deleting just that range of lines in a fashion similar to the command seen in some dialects. clears out variable values, normally accomplished by in most dialects. was similar to CLEAR V, but did not clear the value of shared variables.
Syntax
Branching was supported through, and. The alternate form,, was not supported. One limitation of Wang BASIC, as in the case of the original Dartmouth as well, is that the clause of an IF statement could only be a line number, in contrast to more modern dialects that allow any statement after the. It also lacked Boolean conjunctions like or, so the test could have only a single comparison.One interesting addition to the language was the idea of named routines. The implementation was based on the statement followed by a single quote and then a number from 0 to 255, for instance,. This could then be called using. To further confuse matters, the DEFFN line was a true function definition and could use parameters, like, which could be called with. In allows one to implement multi-line function definitions, which other dialects sometimes offered using the conventional function style rather than using GOSUB. Additionally, named routines in the range 0 to 31 were assigned to the similarly numbed keys on the 2200 keyboard, allowing them to be called directly with a single keypress.
supported comma and semicolon separating parameters, the former moving the cursor to the next 16-character wide column, the later leaving the cursor at the end of the printed value. It supported the function, but not. In common with other "high end" BASICs of the era, Wang BASIC offered formatted output with and a separate "image". The image was defined using a separate line starting with the percent sign, for instance, and then using that format with. Any characters other than the formatting characters were echoed back during the print, so one could define a complete output with something like.
statements could include a prompt, along with a comma-delimited list of one or more variables. Semicolons could not be used in the INPUT, and the cursor always remained at the end of the last printed element during entry.
Math and logic
Like most dialects of the era, variable names could consist of a single uppercase letter or a letter followed by a single digit. It did not support two-letter names. Multiple variables could be set to an initial value using a comma-separated list, for instance,. As with most BASICs, the was always optional. Variables could be made into lists using, as in which made a list of 5 numeric values. or two-dimensional arrays using.Relational operators included the standard set of,,,, and. Trigonometric functions included,,,,,,, and. was an alias for ARCTAN. Trigonometric functions normally operated in radians, but could be set to use degrees using or gradians using, returning to radians with. Other functions included,,, and the pseudo-variable.
Unlike most BASICs, the function did not treat the parameter as a placeholder; any non-zero value made it operate like the RND seen in other BASICs, while a value of zero restarted the number sequence in the same fashion as the statement seen in other BASICs. This is a potential source of bugs when porting from other dialects, which generally ignored the parameter and often used zero as a parameter simply as a common placeholder.
Strings
String variables were supported, and concatenation was supported using the plus operator. In contrast to later BASICs which used dynamic length strings on a heap, like Microsoft, Wang BASIC set all strings to a default length of 16 characters and would ignore any characters assigned beyond that. Unused characters at the end of a string were filled with space characters, and any trailing spaces were ignored in PRINT statements, which is another potential source of problems when porting code to Wang BASIC.The storage length of any single string could be changed using the statement, which in this case used the slightly odd syntax of putting the length immediately after the variable name, like, instead of using parens as in a typical DIM statement. Strings had a maximum length of 64 characters. The syntax allowed lists of strings, for instance made a list of 5 strings of the default 16 character length, while made a list of 10 strings of 20 characters.
There were a small set of string functions. is a general-purpose array slicing command that replaces the DEC/Microsoft-style //. For instance, returns the five characters of A$ starting at character 10. The second parameter was optional, returned everything from the 5th character on. returned the length of the string, ignoring trailing spaces, so would return 3. To further confuse matters, empty string variables always returned a length of 1. Note that the string functions do not include the $, in contrast to most BASICs where these functions would be named, for instance, indicating the return value is a string, not a numeric value.
Data and I/O
In keeping with the Dartmouth model, Wang BASIC included statements for storing constants within the program code, and these were read using the statement, which started at the first data element and then moved a pointer forward to the next element with every READ. could reset the READ pointer, and was expanded from the original Dartmouth version by allowing the pointer to be set particular item in the list, for instance,, which set it to the 10th element. Only 256 values could be entered in DATA statements in total in one program.The statement could be used to redirect output from other BASIC commands to other devices, based on the "address" of the device. For instance, would send the output of subsequent PRINT statements to the printer at address 215, while returned output to the built-in CRT. would do the same for any following LIST statements. SELECT also had an optional following parameter to set the maximum line length, like. One could use SELECT with a variety of pre-defined devices, like CI for "console input" or LIST to redirect the program listing to a different device.
Chaining programs
As machines of the era had very limited amounts of memory, most dialects of BASIC included some way to "chain" programs together to allow a single program to be broken up into smaller modules. In Wang BASIC, this was accomplished with the and statements.declared one or more variables to be "common", or global in modern terminology. A program using chaining would typically declare a number of variables to be common near the top of the code, perhaps. When a separate program module is LOADed, the values in these variables will not be cleared, in contrast to the non-common variables which will be reset. Common variables could be cleared explicitly using, while clears non-common variables and leaves common variables alone. Variables could also be declared non-common using, which reset all common variables to normal, or to reset just the status of A. Confusingly, COM CLEAR also reset any other COM variables defined before A, so the results of COM CLEAR A would be different if the original program used or, in the first example all three would be reset while in the second only A would be reset.
The LOAD command was also used for chaining. One could optionally add start and end line numbers, in which case any existing lines between those limits would be deleted, or from the start line to the end of the program if only one number was specified. The new program is then loaded at that point and execution starts at the start line number, or start of the program if no start line was specified.