SNAP, short for Stylized, Natural, Procedural, is an educational programming language designed by Michael Barnett while working at RCA in 1968 and later used at Columbia University to teach programming in the humanities. It is an imperative programming language, like many languages of the 1960s, but was deliberately verbose, attempting to look more like conversational English in the fashion of HyperText and later languages. Unlike other educational languages of the era, SNAP was not intended to be interactive and was designed to be programmed via punch cards. To save cards, multiple period-separated statements could be written on every card, so the resulting code often looked like a single paragraph.
In 1964, Michael Barnett joined RCA's newly-formed Graphic Systems Division which had been formed to commercialize the photo-typesetting technology they had licensed from Rudolf Hell. Originally known as Digiset, RCA sold the systems under the name Videocomp. About 50 Videocomp systems were sold over its history.
In 1964 and 1965, Barnett developed a page description language known as PAGE-1 to write programs that resulted in Videocomp output, similar to the way the later PostScript language produces pages on laser printers. One of the early applications of this system was to publish Social Sciences Index by the H. W. Wilson Company.
This led to Barnett's interest in the social sciences and his increasing interactions with H. W. Wilson and Columbia University's humanities department. Barnett took a position at H. W. Wilson in 1969. He had also started to teach courses on library automation at the Columbia School of Library Service, and in 1970, computer programming in the humanities. He joined the Columbia faculty full-time in 1975.
The first version of SNAP was written by William Ruhsam of RCA in FORTRAN IV for the RCA Spectra 70, although a version for the IBM 360 in OS-360 was also produced.[a] some time in 1967 or 1968.[b] The language generated a fair amount of comment, especially in the early 1970s, but appears to have had little direct influence on later languages.
SNAP allowed multiple statements to be placed on a single line, and used the period as the statement separator. This produced code that looked like English sentences, and was generally organized into blocks that looked like paragraphs.
SNAP did not use line numbers for editing, and instead used in-code labels for branch targets, as was the case in FORTRAN. In SNAP, a label could be placed anywhere in the code by surrounding the textual name in parentheses like (FIRST LABEL). Labels were not separate statements, and did not require a period after them.
Variables names could contain spaces, which is relatively rare for programming languages even today. Variables could hold strings or numbers, but different syntax was used to assign each one. For numbers, a simple syntax was used, SET I TO 1. SET was also used to perform mathematical operations, like SET I TO THE PRODUCT OF 10 AND J. A simpler syntax was offered for the more common increment and decrement operations, INCREASE M BY 1. or DECREASE M BY 2.
For strings, a longer syntax was typically used, CALL "THIS IS A STRING" THE NEWSTRING. Substrings were accessed using a HyperTalk-like syntax by referring to the ordinal position, for instance, CALL THE J-TH CHARACTER OF NEWSTRING THE NEWCHAR., or CALL THE M-TH THROUGH N-TH CHARACTERS OF THE INPUT THE OUTPUT.
SNAP also offered array-like collections known as "lists". Internally, these were stored as comma-delimited strings. Most of the string-related commands could be used to work with these by adding THE ... LIST. to the end. For instance, one could read a series of cards using READ THE CARD LIST., which would read each card as a separate string into the CARD variable. Items within a list were accessed using the same ordinal syntax, for instance PRINT THE 5-TH CARD, or COPY "NEW STRING" AND CALL IT THE 7-TH CARD. Lists of numbers could be created using SET THE NUMBER LIST TO 1,2,3,4,5.
String variables can also be used as lists, or arrays. This was accomplished using the same ordinal position syntax but referring to the variable name and not the CHARACTER. For instance, CALL "HELLO" THE 1-ST PART. CALL "WORLD" THE 2-ND PART. would create an array called PART with two strings in it.
An important point of the SNAP system is that the CALL statement is not static; it does not define KEY as the character at location J when it is encountered in the code, but when any following code accesses KEY. For instance, SET J TO 1. PRINT KEY. INCREASE J BY 1. PRINT KEY. would result in two different strings being printed. In this fashion, CALL has more in common with the BASIC programming language's DEF FN user-defined functions than it does with the SET statement, which is static.
A static copy of a string could be made by COPY OLDSTRING, AND CALL IT NEWSTRING. Other string functions included APPEND one string TO another string., OVERWRITE string-expression ON THE M-TH [AND SUBSEQUENT] CHARACTER[S] OF string-name., DELETE THE M-TH [THROUGH N-TH] CHARACTER[S] OF string-name. and INSERT string-expression (BEFORE|AFTER) THE M-TH CHARACTER OF string-name.
Unconditional branches were called using CONTINUE, for instance, CONTINUE WITH THE FIRST LABEL. There was also the alternative form REPEAT THE FIRST LABEL.. There was no difference between them, although the context of the surrounding code generally meant one form or the other was more natural to read. One could also refer to the start of the program with CONTINUE FROM THE BEGINNING. "As follows" could be used to refer to the next statement, CONTINUE AS FOLLOWS., which could be used to clarify branches.
Conditional branches used an if-then(-else) structure:
As in most languages, the OTHERWISE section was optional. Note the use of AND to make a compound statement within the then section, offering a block structure. For string comparisons, one used IS or the optional IS THE SAME AS.
SNAP included a number of other keywords that had no behaviour of their own that were added simply for syntactic sugar. Among them were THE, A, FROM which the programmer could add in many locations to make the syntax more readable. Typical uses included READ A RECORD and REPEAT FROM THE LOOP START.
From A Natural Language. Variables and expressions are in italic. Optional forms are separated by vertical bars, |. Braces surround optional items, while angle-brackets surround required items that have more than one form. value refers to a numeric constant or variable, string to a quote-delimited string constant or string variable.
Flow control:
Mathematics:
String manipulation:
Input/output related:
Others:
Here is the largest example of a practical program given in SNAP, which reads strings from cards and then prints out the individual words found in them:
For clarity, the following version simply spaces out the statements onto separate lines and adds appropriate whitespace:
The program READs a single card and assigns the string data found on it to the variable named RECORD. It then sets up two pointers, I and J. A function called KEY is CALLed that returns the Jth character of RECORD.
It then examines the Jth character to see if it is a word-breaking character or off the end of the string. If neither of these are true, it moves to the next character and tries again. This loop continues until it finds a word-breaking character or falls off the end of the card at the 80th character. If it has hit the end of the card, it jumps to the OUTPUT ACTION.
If it does find a word-breaking character, it jumps to BACKUP, which backs up one character to skip the punctuation it just examined. It then naturally falls through to the OUTPUT ACTION. That code prints out the string between the starting position in I to the current position in J.
If we have not reached the end of the card, move J forward by two characters to skip over the punctuation we previously avoided and move the pointer to the start of the next (potential) word. Then set I to J to position our next word's starting position from this point, and return to LOOP START. If we are at the end of the card, start the entire program over and read another card.