-
Notifications
You must be signed in to change notification settings - Fork 2
Snobol
The Snobol language today feels pretty ancient. Introduced in 1962, its big claim to fame was popularizing regular expressions; as a matter of fact, the language actually implemented them as a built-in data type - the Pattern. Establishing the regular expression is actually a pretty big legacy, and in the 70's Snobol was heavily used for text processing. But the language is fairly primitive in other ways - for instance, GOTO is the primary means of control flow, and it has only crude support for procedural programming. It was mainly designed as a text processing language at the time, with the heavy lifting reserved for more heavy-weight languages like COBOL, Fortran, and Lisp, and with its later descendents being languages like Awk and Perl.
Each statement in Snobol has three parts - a label, an operation, and a GOTO, and each part is optional. Here is Euler1 in Snobol:
* Euler1 in Snobol
DEFINE('Euler(size)') :(Exit)
Euler i = 1
Loop EQ(REMDR(i, 3), 0) :F(Try_5)
Euler = Euler + i :(Next)
Try_5 EQ(REMDR(i, 5), 0) :F(Next)
Euler = Euler + i
Next i = i + 1
LE(i, size) :S(Loop)
Done :(RETURN)
Exit
OUTPUT = Euler(999)
END
In the above example, labels are in the left-most column, operations are in the middle, and GOTOs are on the right. GOTOs have an optional S or F predicate to make them conditional on Success or Failure. I think it was all these labels that finally pushed Edsger Dijkstra too far. Surprisingly, it only took me maybe 20 minutes to write this, despite knowing nothing about the language previously. Its error messages didn't seem terribly useful, and the compiler is somewhat anal about syntax, but it's not terrible.
To run this, I used Snobol4 (I don't even want to think how crude Snobol1 must have been). Yum-install snobol and snobol-devel. Then simply call snobol4 with your code:
$ snobol4 euler.snobol
The Macro Implementation of SNOBOL4 in C (CSNOBOL4) Version 1.2
by Philip L. Budne, December 9, 2008
SNOBOL4 (Version 3.11, May 19, 1975)
Bell Telephone Laboratories, Incorporated
No errors detected in source program
233168
Normal termination at level 0
euler.snobol:16: Last statement executed was 15
$
Return home