Friday, December 16, 2016


I've been playing around a bit with SNOBOL.  I heard once that you should never bother learning a new programming unless it changes the way you think (oh here it is Perlis epigram 19):
  • 19: A language that doesn't affect the way you think about programming, is not worth knowing.

SNOBOL definitely changes the way you think.  It is based on pattern matching, and side effects that occur during matches, or attempted matches.  Blank space is not just significant (a la Python) it is an actual operator: concatenation.  SNOBOL has procedure definitions, and the procedures can be recursive, but it doesn't really have the notion of a procedure body.  You define the name, the arguments, local variables, and the entry point (all but the name are optional).

If you don't put a jump at the end of the definition then it will happily start executing the "body" of the code, and may give you an error, since of course the arguments will all be null, and you were maybe relying on something being there. 

There are no do or for or while loops, but every statement can have an unconditional or (up to two) conditional gotos appended.  Since there are no actual procedure bodies, you can have bits of code shared by multiple procedures (e.g. error returns).  There can be jumps from all over into that code, but of course RETURN will still return from the current procedure. Take that Dijkstra!

I/O is greatly simplified by the use of variables that can take their value from input, or which when set send their value to the output.  For example, Hello World looks like this:

 OUTPUT = 'Hello World'

I can't think of another language with that combination of very high level and very low level features, but when you realize that it dates from about 1969, it makes a a bit more sense.

What got me playing with it?  I recently picked up a copy of a book entitled "Programming Languages, A Grand Tour" (edited by Ellis Horowitz) at a Goodwill store in Albuquerque.  It is an anthology of articles on programming languages, from the early 80s.  Lots of great things in it, including the article by Backus in which introduced the phrase "Von Neumann bottleneck".

The first article in the book is by P. Wegner, titled "Programming Languages -- The First 25 Years" and contains a list of 30 milestones.  To give you some idea, M1 is the Von Neumann's EDVAC report, M5 is FORTRAN, M12 is LISP and M26 is Structured Programming.  SNOBOL is M13.  That reminded me I'd seen a book on SNOBOL at a friends house back in the 70s, and ....

Another point of interest in the book is an early paper on C. It mentions the disadvantages of having printf in a library rather than in the language.  Essentially the problem is that if you change the type of a variable you have to change the %d or what have you to match it, whereas if printf were in the language it could "know" the type, and adjust itself.  This was, I think, part of the motivation for adding cout to C++.  The (much newer) Go programming language fixes this by adding reflection, if I understand that correctly.  SNOBOL however had solved this long before: OUTPUT does something sensible with whatever value you provide it.