SNOBOL4

Back when we were brave young souls, SNOBOL was that language that we were all "gonna learn someday." Not that anybody ever did. And I'm not sure why we wanted to. Perhaps it was because SNOBOL was weird, wonderful, and geeky-cool.

This was back in the late 60's and early 70's, when learning a new computer language was not trivial. First, where are you going to get a manual describing the language? There was no web, so you went to the library. If the library didn't have a SNOBOL book, you had to search the bookstores. I found a copy of Griswold's Green Book in a little book store in Fayettville, NC.

The next step was getting access to a computer. Computers cost several million dollars each, so you couldn't just buy one. You had to go to school or get a computer job somewhere. If you were really lucky you could find a school where they taught a SNOBOL course. (At the time, a significant portion of the undergraduate Computer Science curriculum was devoted to language courses. One language per course.)

Getting access to a computer was not easy, but it was doable if you were determined. But then the big question was, Does your computer have a SNOBOL compiler? The answer was almost certainly NO. Most people would give up at this point. If you were a systems administrator, you might be able to talk your boss into installing a SNOBOL compiler, provided it didn't cost anything. But where would you get it? Computer companies didn't offer SNOBOL compilers. If you knew about somebody somewhere who wrote one or had one that somebody else wrote you might be able to send them a blank tape and $20-30, and they just might make a copy and send it to you. Then once you got the tape, you might actually get it to work. Then you could finally achieve your dream of learning SNOBOL!

SNOBOL was the first language to treat alphanumeric data in any serious way. You could process such data in COBOL, but this was mostly just moving it around. With SNOBOL you could manipulate individual characters in a straightforward way. This is no longer a big deal, but one interesting feature that SNOBOL has is pattern matching. SNOBOL patterns are more powerful than regular expressions, and I don't believe that they are available in any modern language.

If you hate goto-less programming SNOBOL is for you. There's no IF statement and no real loop structures. (Loops exist but not in the conventional way.) There are only goto operations. Implicit goto operations at that. The labels :F(LOOP) :S(LOOP) and :(LOOP) are added to another statement to form a goto. This goto is executed after the statement containing it completes execution. Some statements can succeed or fail, and the :S and :F labels tell where to go on success or failure of the containing statement. For example the statement EQ(X,0) succeeds if X is equal to zero and fails otherwise. For functions there are two return statements RETURN for success and FRETURN for failure. Of course, the :(LOOP) type labels are for unconditional gotos.

Labels and comments start in column 1. * in column 1 signifies a comment. Executable statements without labels must start somewhere beyond column 1.

The following program compiles and runs using the old MSDOS Vanilla compiler.

*////////////////////////////////////////////////////////// *// Name: Peter M. Maurer *// Program: Sieve of Eratosthenes *// Due: Never *// Language: SNOBOL4 *////////////////////////////////////////////////////////// * define the sieve data structure * everything is potentially prime until proven otherwise CANDIDATES = ARRAY('0:1000', 1) * Neither 1 nor 0 is prime, so flag them off CANDIDATES<0> = 0 CANDIDATES<1> = 0 * start the sieve with the integer 0 I = 0 LOOP1 LT(I,1000) :F(ELOOP1) * advance to the next un-crossed out number. * this number must be a prime EQ(CANDIDATES<I>,0) :F(ELOOP2) I = I + 1 :(LOOP1) ELOOP2 J = 2 K = I * J LOOP3 LT(K,1000) :F(ELOOP3) CANDIDATES<K> = 0 J = J + 1 K = I * J :(LOOP3) * advance to the next candidate ELOOP3 I = I + 1 :(LOOP1) ELOOP1 I = 0 * all uncrossed-out numbers are prime (and only those numbers) * print all primes LOOP4 LT(I,1000) :F(ELOOP4) NE(CANDIDATES<I>,0) :F(SKIP1) OUTPUT = I " is prime" SKIP1 I = I + 1 :(LOOP4) ELOOP4 I = 0 END

Click Here for the actual code.