|RPN in BASIC|
The name ‘BASIC’ is an acronym for Beginner's All-purpose Symbolic Instruction Code. The language was introduced in 1964, in an attempt to make elementary programming easier to students, particularly non-science ones. The first versions of BASIC were used in teaching mathematics disciplines to liberal arts students.
The more ambitious goal of the authors was to make the use of a computer easier to people, be they students, college or university staff or other who would need to program non-professionally, as an aid to their other activities. The programming language was a necessary and important but not the only part of the project. Also essential was the creation of a time-sharing system, through which users could interact with the computer, independently of each other, by means of simple commands, expressed as widely understandable English words.
As the authors testify, the free access to the computer system, a rarity in those years but available at Dartmouth College (where the language was created) also contributed to the success of their endeavour. Other interactive programming systems already existing at the time (JOSS, CORC) were far less successful than BASIC.
The authors of BASIC considered (then already old dialects of) Fortran and Algol 60 as starting points for their design, and ended-up with a language that was partly a very simplified version of Fortran, and partly original.
The original BASIC could work with just numeric data and offered only basic control structures: conditional, unconditional, and computable gotos, arithmetic loop, and a very week form of sub-routines. There was no distinguishing between different kinds of numbers, e.g. integers and reals. One could define arrays of dimensions one and two, then called lists and tables. Variables did not need declaring to be used, except when arrays, and in fact even non-declared variables could be used as arrays of size 10.
The original implementation was compiled, as the speed of interpreting was considered prohibiting to the intended use in a time-sharing system. Also for efficiency reasons, the language was so designed that it could be compiled in a single pass.
The syntax of BASIC was (and still is, with some exceptions) line-oriented. Each line of the program contained a single statement, and a statement had to fit entirely on a single line. Each kind of statement in BASIC began with a distinguishing keyword:
LET for assignment,
IF for conditional jump,
Time-sharing was instrumental in making the system friendly through providing interactive (rather than batch) communication with the user. The communication, like the language itself, was line-oriented: each single action consisted of typing in and sending to the system a line of text. If a line started with a digit, it was considered to be a statement, with the corresponding ordinal number, which was to be added to the program or to replace an existing statement in it. Otherwise the line had to start with a letter and was considered a command to the system (a monitor command). This use of the line numbers allowed for editing the program line by line in the absence of a true text editing program – there was no screen-oriented text editors at the time, nor were they possible in view of the severe resource restrictions typical of the computers of that time.
The monitor commands ensured executing a program (
RUN), printing it (
LIST), storing it under a name (
SAVE), canceling a program (
STOP) and other necessary actions. There was no separate command for compiling –
RUN both compiled and ran the program, or issued error messages if the compilation was unsuccessful. Thus compilation remained ‘invisible’ to users. In fact, in the original implementation of BASIC, and in many others thereafter, the language and its supporting programming system were perceived as indistinguishable.
Despite the system being interactive, BASIC itself did not, initially, provide any means for writing interactive programs. Its
INPUT statement for reading data into the program was introduced only later on. Before that, if a series of (numeric) values were to be fed to the program, they would be hard-written in it, in one or more
DATA statements, special by being non-executable, and then read by
READ statements. Thus, one needed to change the program in order to run it on different data.
It should be noted that the original BASIC was not only a great simplification of its major influences such as Fortran. In a number of ways, it was also a very constraining language. For example, variable names could only consist of a single letter, possibly followed by a digit. More importantly, the provision of functions and sub-routines was very limited; programs were mainly monolithic structures.
The following two quotes from the original manual (see the link below) are indicative.
‘The name of a defined function must be three letters, the first two of which are FN.’
‘The user must be very careful not to write a program in which a GOSUB appears inside a subroutine which itself is entered via a GOSUB; it just won't work.’
GOSUB was the command for invoking what BASIC considered a ‘sub-routine’. It was a kind of a jump which ‘took a note’ of where the invocation occurred so that a subsequent
RETURN statement passed the control back to the statement following
GOSUB. The ‘sub-routine’ was just an arbitrary part of the program, and could get executed through
GOSUB as well as through ordinary jump, or simply due to being reached in the normal order of execution. There was no notion of arguments/parameters, or of local variables. And what the second of the above quotes says is that only a single level of call nesting was permitted.
As for functions, mentioned in the first quote, each such function was a single expression, again without local variables. Even the function parameter was just one of the variables in the program, so that, when such a parameter received a new value due to calling the respective function, it would side-effect any other point in the program where the same name was used.
In the years after BASIC was born, the ease of learning, using and implementing it lead to increasing interest in the language and eventually – its wide and steady presence in the programming landscape. The designers of the language applied considerable effort into promoting it. Many new implementations emerged on different architectures. The coming into existence of 8-bit personal and home computers gave an enormous boost to BASIC's popularity which continued with the 16-bit PCs. Many of these implementations were interpretive, and often ROM-resident.
One consequence of the explosive growth of BASIC was that almost all implementations turned to be different dialects. A most influential line of implementations was that of Microsoft which started with an interpreter for an 8-bit microcomputer and culminated in the QuickBASIC compiler for MS DOS. (Microsoft then abandoned it in favour of their Visual Basic product – still later remolded into Visual Basic .NET – which is so different from all other BASICs that perhaps should be more properly considered a new language.) Another dialect of BASIC is being used as a main scripting language in Microsoft's Windows o.s. and Office package.
Along with its usage growth, BASIC evolved by removing its most apparent limitations and adding some useful new features. One early and important addition was the introduction of a string datatype. Strings were dynamically sized, and because they were the only other datatype besides numbers, it was decided that string variables would be notationally different by ending in a $-sign – a well known distinctive feature of BASIC's syntax. Some dialects – first of all the original BASIC – incorporated matrix arithmetic. Most BASICs made it possible to treat arithmetic values as Booleans, similar to C and other languages. (The absence of Boolean values or their equivalent was a notable omission in the original BASIC, and actually still is in its present-day version True BASIC – see the link below.)
New conditional and looping control structures were introduced, similar to those in other imperative languages, that obviated one of the reasons for which line numbers existed. Since line numbers were also no more needed for editing, most versions of BASIC eventually made them optional or dropped them altogether.
At some point in its evolution BASIC inevitably acquired proper sub-routines, with locally scoped variables and in particular parameters, which quickly replaced the
RETURN in most implementations. Like Fortran, today's BASIC employs argument passing by reference.
A valuable feature of present-day BASICs is the support of dynamically resizable arrays. It fits well the similar string property, and makes possible creating a number of dynamic data structures, thus serving most instances where a language such as e.g. C would have to resort to low-level memory allocation and reclamation.
Two attempts were made for standardizing the language at ANSI and ISO. The standards do exist, and are known as ANSI/ISO ‘Minimal’ and ‘Full’ BASIC, but they did not have the intended impact as almost no implementation abides strictly by their prescriptions or even refers to them. ‘Minimal BASIC’ is close to the original language, while ‘Full BASIC’ is more or less the base of most modern dialects.
Today, BASIC continues to be used for writing various kinds of programs, and is still considered by many as a good language for introductory programming teaching in schools and colleges. Its numerous implementations differ most notably in the content of their accompanying libraries, the supporting programming environments, and other extra-language features.
The original manual and reference for the language (1964)
T. E. Kurtz, BASIC, ACM SIGPLAN Notices, Vol. 13, #8 (August 1978), pp. 103-118:
an article on the history of BASIC, from one of its authors