Dartmouth Basic

This is the original dialect of BASIC as it was invented by Kimmeny and Kurz. Although this language was wildy successful it was panned by many famous computer scientists. Later dialects of BASIC were even more successful, the most notable of which is Visual Basic, which is one of the world's most popular development languages.

This BASIC has some definite peculiarities. Every line must have a line number. The lines could be typed in any order, but they would be sorted into ascending order before the program was compiled. (Yes, compiled.) The line numbers are an integral part of the program, because they are the target of all GOTO and IF statements.

There is one looping construct, the FOR loop which has one of the two following forms.

FOR I = 1 TO N

FOR I = 1 TO N STEP K

The 1, N and K could be replaced by arbitrary arithmetic expressions. Loops were terminated by the NEXT statement as follows.

NEXT I

The IF statement had a single form as follows.

IF X<Y THEN 25

X and Y could be replaced by arbitrary arithmetic expressions. Comparisons operators were not considered to be arithmetic operators. The < sign could be replaced with one of >, <=, >=, = or <>. No Boolean operators were allowed. The number 25 is a line number. Control would be transfered to this line if the comparison were true, otherwise the next statement in line would be executed.

Every program had to end with an "END" statement, and assignment statements had to begin with the "LET" keyword. Spaces were optional except in quoted strings.

Because the line numbers had to be left-justified, it was essentially impossible to indent code. This sort of thing was quite rare at the time anyway.

Dartmouth Basic was the first programming language I learned, and I wrote several programs in it. One constant problem was the line numbers. If you wanted to make extensive changes to your code, you had to insert lines by creating new line numbers that fit between the existing ones. That's why most line numbers are multiples of 10. Note the lines I inserted after line 150 below. When things got too tight, there was a RENUMBER editor command that could be used to renumber the lines and also update the GOTO and IF statements to keep them in sync. Unfortunately, it was possible to utterly destroy your program if you weren't careful with this. The Dartmouth Timesharing system provided several languages in addition to BASIC. FORTRAN and ALGOL were also available. If you told the editor you were editing a FORTRAN program, but it was really a BASIC program, and then you renumbered it, it would renumber the lines, but not the GOTO statements. There was no such thing as an undo. You could spend hours recovering from this mistake.

The program below compiles and runs under the YABASIC compiler/interpreter as long as 5 changes are made to the code. The statement IF X<Y THEN 25 is illegal in YABASIC and must be replaced with the statement IF X<Y GOTO 25. This amounts to changing the keyword THEN to the keyword GOTO on five different lines. See line 153 below for the list of lines that need to be changed.

The program will run unchanged under MS DOS QBASIC, if you can manage to locate a copy.

100 REM ////////////////////////////////////////////////////////// 110 REM // Name: Peter M. Maurer 120 REM // Program: Sieve of Eratosthenes 130 REM // Due: Never 140 REM // Language: Dartmouth Basic 150 REM ////////////////////////////////////////////////////////// 153 REM Modlines: 260,290,300,370,470 157 REM Change THEN to GOTO for YABASIC 160 DIM C(999) 170 REM define the sieve data structure 180 FOR I = 0 TO 999 190 REM everything is potentially prime until proven otherwise 200 LET C(I) = 1 210 NEXT I 220 REM Neither 1 nor 0 is prime, so flag them off 225 LET C(0) = 0 230 LET C(1) = 0 240 REM start the sieve with the integer 0 250 LET I = 0 260 IF I>=1000 THEN 440 270 REM advance to the next un-crossed out number. 280 REM this number must be a prime 290 IF I >= 1000 THEN 440 300 IF C(I) <> 0 THEN 330 310 LET I = I+1 320 GOTO 290 330 REM come here when prime found 340 REM cross out all multiples of the prime, starting with 2*p. 350 LET J = 2 360 LET P = I * J 370 IF P >= 1000 THEN 420 380 LET C(P) = 0 390 LET J = J+1 400 LET P = I * J 410 GOTO 370 420 LET I = I+1 430 GOTO 260 440 REM all uncrossed-out numbers are prime 450 REM print all primes 460 FOR I = 0 TO 999 470 IF C(I) = 0 THEN 490 480 PRINT I," is prime" 490 NEXT I 500 END

Click Here for the actual code.