This is a card in Dave's Virtual Box of Cards.

Getting started with Snobol

Page created: 2024-08-03
Updated: 2025-05-06

Update: I ended up taking the dive into Snobol and here’s my impressions of the SNOBOL4 language after using it for a while.

I’ve always been curious about SNOBOL, the "StriNg Oriented symBOlic Language". It’s one of those languages you hear people raving about in terms of being superior in a particular niche. In SNOBOL’s case. the niche is string pattern matching.

But like forth, it took a long time before I got the urge to really dive in and try it for myself.

As with many "historic" languages, there are free versions floating around out there.

Get SNOBOL

I snagged a copy of SNOBOL4 at this excellent website:

Specifically, release 2.3.2 of "CSNOBOL4", which is Phil Budne’s actively maintained port of the original Bell Labs SNOBOL. (Actually, that’s a really cool thing of its own and and I invite you to read a bit more about The Snobol Implementation Language (SIL)!)

It follows the familiar C dance:

$ tar -xf snobol4-2.3.2.tar.gz
$ cd snobol4-2.3.2
$ make
$ sudo make install

That installed the executable as /usr/local/bin/snobol4-2.3.2.

I made a handier symlink name:

$ cd /usr/local/bin/
$ sudo ln -s snobol4-2.3.2 snobol4

Get a reference

I grabbed a copy of "the green book", The SNOBOL4 Programming Language (raganwald.com) by Griswold, et al.

Hello World

Making a first Hello World was ridiculous. All of the SNOBOL resources harken back to an era when you were likely to have plenty of time to read, but maybe not much access to a computer.

So it’s like Chapter 4 before you see anything running.

I just wanted to know if the dang thing worked.

The first "gotcha" with SNOBOL is that printing something to the screen requires setting the OUTPUT variable.

OUTPUT = 'Hello world!'

(Fun fact: The PUNCH variable is similar, but it writes to your punch card puncher. You’ve got one of those hooked up, right?)

The second "gotcha" is that SNOBOL is line-oriented and based on positional fields, all of which are optional:

<label> <subject> <pattern> = <object> : <transfer>

So my first attempts at outputting a 'hello world' string looked like this:

$ snobol4
The Macro Implementation of SNOBOL4 in C (CSNOBOL4B) Version 2.3.2
    by Philip L. Budne, Janurary 1, 2024
SNOBOL4 (Version 3.11, May 19, 1975)
BLOCKS (Version 1.10, April 1, 1973)
    Bell Telephone Laboratories, Incorporated

snobol4> output = 'Hello world!'
        OUTPUT = 'Hello world!'
                ^
-:1: *** Erroneous subject

snobol4>

The Erroneous subject error means that I accidentally put something in the "subject" portion of the line.

The secret is to indent the statement (either a tab or space will do) so you’re not starting with output as a label:

snobol4>        output = 'Hello world!'

Finally, you have to end your program with the 'END' label:

snobol4> END
No errors detected in source program

Hello world!
Normal termination at level 0

While the SNOBOL interpreter appears to take a program interactively REPL-style, there’s no recovering from mistakes. So unless you can type your programs perfectly from start to finish, you really want to feed it files.

Here’s a full hello.sno and the result:

$ cat hello.sno
    output = 'Hello world!'
END

$ snobol4 hello.sno
Hello world!

I later found out that Wikipedia has some nice small examples, including a Hello World on the SNOBOL (Wikipedia.org) page. That would have saved me a lot of time. Live and learn.