SNAP (programming language)

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.

SNAP
ParadigmImperative
Designed byMichael Barnett, William Ruhsam
First appeared1970 (1970)

History

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.[1]

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.[2] One of the early applications of this system was to publish Social Sciences Index by the H. W. Wilson Company.[3]

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.[4] He joined the Columbia faculty full-time in 1975.

The first version of SNAP was written by William Ruhsam of RCA in FORTRAN IV[5] for the RCA Spectra 70, although a version for the IBM 360 in OS-360 was also produced.[lower-alpha 1] some time in 1967 or 1968.[6][lower-alpha 2] The language generated a fair amount of comment, especially in the early 1970s,[7] but appears to have had little direct influence on later languages.

Description

General concepts

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.[8]

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 parenthesis like (FIRST LABEL). Labels were not separate statements, and did not require a period after them.[9]

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.[9]

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.[9]

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.[10]

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.[9]

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.[11]

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.[12]

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.[13]

Conditional branches used an if–then(–else) structure:

IF J IS LESS THAN 80 INCREASE J BY 1, AND REPEAT FROM THE FIRST LABEL, OTHERWISE CONTINUE AS FOLLOWS.

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.[12]

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.[13]

Statements

From A Natural Language.[6] 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:

(string constant)
defines a program label
<CONTINUE|REPEAT> [WITH|FROM] <label|THE BEGINNING [OF THE PROCEDURE]|THE NEXT SENTENCE|AS FOLLOWS>
jump to the named label, the start of the program, or continue on to the next statement
IF value|string <IS|ARE> [THE SAME AS] value|string expression[,AND expression...] [, OTHERWISE expression[,AND expression...]]
if-then-else construct, with any number of expressions within the then and else sections
-string comparisons allowed substring tests like IS THE value[-TH] AND [SUBSEQUENT|PRECEDENT] CHARACTERS OF string
-numeric comparisons included EQUAL TO, LESS THAN, GREATER THAN, UNEQUAL TO, GREATER THAN OR EQUAL TO, LESS THAN OR EQUAL TO
-the end-of-file could be tested with IF THE INPUT IS EXHAUSTED.
TERMINATE
stops the program
EXECUTE
runs the program. Was to be expanded to allow execution to start at a given label, but was not implemented in the versions described in the references

Mathematics:

SET numeric variable TO value - assigns a value to a numeric variable
SET numeric variable TO THE [SUM|DIFFERENCE|PRODUCT|QUOTIENT|REMAINDER|CEILING|GREATER|LESSER] OF value AND value
perform mathematical functions with two operands
INCREASE variable BY value - simplified notation for addition
DECREASE variable BY value - ...and subtraction

String manipulation:

CALL string [THE] string variable - create a string function
[FORM A] COPY [OF] string AND CALL IT [THE] string variable - copy a string from one variable to another
APPEND string TO string variable - append a string variable with another string
LINK string TO string - appends the first string to the second, but does not copy it, future changes to the second string will be tracked as in a CALL
DELETE THE value[-TH] [THROUGH value [-TH]] CHARACTER[S] OF string variable - trim a string from the selected character on, or a given range
OVERWRITE string ON THE value[-TH] [AND SUBSEQUENT|PRECEDENT] CHARACTER[S] OF string variable - replaces one character of a string with another, or that character and those running forward or backward from the selected position.

Input/output related:

SELECT number [FOR <INPUT|OUTPUT>]
used to select a device for other input/output operations
READ [A|THE] string variable
reads a single punch card
REQUEST [A|THE] string variable
asks for user input from the console
FETCH [A|THE] string variable
reads one record from the most recently SELECTed device
PRINT [A|THE] variable
sends output to the line printer
TYPE [A|THE] variable
sends output to the console
PUNCH [A|THE] variable
sends output to the card punch
PERFORATE [A|THE] variable
sends output to paper tape
WRITE [A|THE] variable
sends data to the last SELECTed device

Others:

CONTROL various
a temporary command used to control the language as new features were added
RESERVE SPACE FOR number <CHARACTERS IN variable|ELEMENTS IN [THE] variable LIST
similar to the DIM statement in BASIC, sets aside a specified amount of memory to hold a string, or a given number of strings from a list. Using RESERVE avoided memory operations as the string or list was built and improved performance

Example

Here is the largest example of a practical program given in SNAP,[14] which reads strings from cards and then prints out the individual words found in them:

READ A RECORD. SET I TO 1. SET J TO 1. CALL THE J-TH CHARACTER OF THE RECORD THE
KEY. (LOOP START) IF THE KEY IS " " CONTINUE WITH THE BACKUP. IF THE KEY IS ""
CONTINUE WITH THE BACKUP. IF THE KEY IS "." CONTINUE WITH THE BACKUP. IF J IS
LESS THAN 80 INCREASE J BY 1, AND REPEAT FROM THE LOOP START, OTHERWISE CONTINUE
WITH THE OUTPUT ACTION. (BACKUP) DECREASE J BY 1. (OUTPUT ACTION) PRINT THE I-TH
THROUGH J-TH CHARACTERS OF THE RECORD. IF J IS LESS THAN 79 INCREASE J BY 2, SET
I TO J, AND REPEAT FROM THE LOOP START, OTHERWISE REPEAT FROM THE BEGINNING.
EXECUTE

For clarity, the following version simply spaces out the statements onto separate lines and adds appropriate whitespace:

  READ A RECORD.
  SET I TO 1.
  SET J TO 1.
  CALL THE J-TH CHARACTER OF THE RECORD THE KEY.
(LOOP START)
  IF THE KEY IS " " CONTINUE WITH THE BACKUP.
  IF THE KEY IS "" CONTINUE WITH THE BACKUP.
  IF THE KEY IS "." CONTINUE WITH THE BACKUP.
  IF J IS LESS THAN 80 INCREASE J BY 1, AND REPEAT FROM THE LOOP START, OTHERWISE CONTINUE WITH THE OUTPUT ACTION.
(BACKUP)
  DECREASE J BY 1.
(OUTPUT ACTION)
  PRINT THE I-TH THROUGH J-TH CHARACTERS OF THE RECORD.
  IF J IS LESS THAN 79 INCREASE J BY 2, SET I TO J, AND REPEAT FROM THE LOOP START, OTHERWISE REPEAT FROM THE BEGINNING.
EXECUTE

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.

Notes

  1. The Spectra 70 is similar enough to the IBM 360 to make porting straightforward.[6]
  2. The earliest published references date from 1968, but it may date to the earlier year.

References

Citations

  1. Belzer, Jack; Holzman, Albert; Kent, Allen, eds. (December 1976). "Computer-Aided Composition". Encyclopedia of computer science and technology. CRC Press. p. 350. ISBN 9780824722555.
  2. Pierson, John (1972). Computer composition using PAGE-1. Wiley Interscience. p. vi. ISBN 9780471689553.
  3. "Obituary of Michael Barnett (1929-2012)". Physics Today. 29 March 2012. doi:10.1063/PT.4.1776.
  4. Barnett, Michael (1971). "Computer hardware and software for librarians". In Fasana, P.J.; Veaner, A. (eds.). Collaborative library systems development. MIT Press.
  5. Barnett & Ruhsam 1968, p. 47.
  6. Barnett & Ruhsam 1968, p. 48.
  7. Raskin, Jeffrey (January 1971). "Programming Languages for the Humanities". Computers and the Humanities. 5 (3): 155–158. doi:10.1007/BF02402180. S2CID 61028443.
  8. Barnett 1970, p. 225.
  9. Barnett 1970, p. 228.
  10. Barnett & Ruhsam 1968, p. 49.
  11. Barnett 1970, p. 231.
  12. Barnett 1970, p. 232.
  13. Barnett 1970, p. 230.
  14. Barnett 1970, p. 229.

Bibliography

Further reading

This article is issued from Wikipedia. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.