SNAP (programming language)
{{about|a 1960s educational programming language|the modern blocks-based system|Snap! (programming language)}}
{{short description|Education programming language from 1960s}}
{{Infobox programming language
| name = SNAP
| screenshot =
| screenshot caption =
| paradigm = Imperative
| designers = Michael Barnett, William Ruhsam
| released = {{Start date and age|1970}}
| dialects =
| influenced by =
}}
SNAP, short for Stylized, Natural, and 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.
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.{{cite encyclopedia |title=Computer-Aided Composition |encyclopedia=Encyclopedia of computer science and technology |editor-first1=Jack |editor-last1=Belzer |editor-first2=Albert |editor-last2=Holzman |editor-first3=Allen |editor-last3=Kent |authorlink3=Allen Kent |publisher=CRC Press |date=December 1976 |url=https://books.google.com/books?id=c09mvQEACAAJ |page=350|isbn=9780824722555 }}
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.{{cite book |first=John |last=Pierson |title=Computer composition using PAGE-1 |publisher=Wiley Interscience |date=1972 |page=vi |url=https://books.google.com/books?id=57dDAAAAMAAJ|isbn=9780471689553 }} One of the early applications of this system was to publish Social Sciences Index by the H. W. Wilson Company.{{cite journal |date=29 March 2012 |title=Obituary of Michael Barnett (1929-2012) |journal=Physics Today|issue=3 |doi=10.1063/PT.4.1776 |last1=Capitani |first1=Joseph F. |page=3333 |bibcode=2012PhT..2012c3333. }}
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.{{cite encyclopedia |first=Michael |last=Barnett |title=Computer hardware and software for librarians |editor-first1=P.J. |editor-last1=Fasana |editor-first2=A. |editor-last2=Veaner |encyclopedia=Collaborative library systems development |publisher=MIT Press |date=1971}} He joined the Columbia faculty full-time in 1975.
The first version of SNAP was written by William Ruhsam of RCA in FORTRAN IV{{sfn|Barnett|Ruhsam|1968|p=47}} for the RCA Spectra 70, although a version for the IBM 360 in OS-360 was also produced.{{efn|The Spectra 70 is similar enough to the IBM 360 to make porting straightforward.{{sfn|Barnett|Ruhsam|1968|p=48}}}} some time in 1967 or 1968.{{sfn|Barnett|Ruhsam|1968|p=48}}{{efn|The earliest published references date from 1968, but it may date to the earlier year.}} The language generated a fair amount of comment, especially in the early 1970s,{{cite journal |title=Programming Languages for the Humanities |first=Jeffrey |last=Raskin |authorlink=Jef Raskin |journal=Computers and the Humanities |volume=5 |number=3 |date=January 1971 |pages=155–158|doi=10.1007/BF02402180|s2cid=61028443 }} 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.{{sfn|Barnett|1970|p=225}}
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 {{code|(FIRST LABEL)}}. Labels were not separate statements, and did not require a period after them.{{sfn|Barnett|1970|p=228}}
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, {{code|SET I TO 1.|cobolfree}} {{code|SET}} was also used to perform mathematical operations, like {{code|SET I TO THE PRODUCT OF 10 AND J.|cobolfree}} A simpler syntax was offered for the more common increment and decrement operations, {{code|INCREASE M BY 1.}} or {{code|DECREASE M BY 2.}}{{sfn|Barnett|1970|p=228}}
For strings, a longer syntax was typically used, {{code|CALL "THIS IS A STRING" THE NEWSTRING.}} Substrings were accessed using a HyperTalk-like syntax by referring to the ordinal position, for instance, {{code|CALL THE J-TH CHARACTER OF NEWSTRING THE NEWCHAR.|cobolfree}}, or {{code|CALL THE M-TH THROUGH N-TH CHARACTERS OF THE INPUT THE OUTPUT.|cobolfree}}{{sfn|Barnett|1970|p=228}}
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 {{code|THE ... LIST.}} to the end. For instance, one could read a series of cards using {{code|READ THE CARD LIST.|cobolfree}}, 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 {{code|PRINT THE 5-TH CARD|cobolfree}}, or {{code|COPY "NEW STRING" AND CALL IT THE 7-TH CARD.|cobolfree}} Lists of numbers could be created using {{code|SET THE NUMBER LIST TO 1,2,3,4,5.|cobolfree}}{{sfn|Barnett|Ruhsam|1968|p=49}}
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 {{code|CHARACTER}}. For instance, {{code|CALL "HELLO" THE 1-ST PART. CALL "WORLD" THE 2-ND PART.|cobolfree}} would create an array called PART with two strings in it.{{sfn|Barnett|1970|p=228}}
An important point of the SNAP system is that the {{code|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, {{code|SET J TO 1. PRINT KEY. INCREASE J BY 1. PRINT KEY.|cobolfree}} would result in two different strings being printed. In this fashion, {{code|CALL}} has more in common with the BASIC programming language's {{code|DEF FN}} user-defined functions than it does with the {{code|SET}} statement, which is static.{{sfn|Barnett|1970|p=231}}
A static copy of a string could be made by {{code|COPY OLDSTRING, AND CALL IT NEWSTRING.|cobolfree}} 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.
{{sfn|Barnett|1970|p=232}}
Unconditional branches were called using {{code|CONTINUE}}, for instance, {{code|CONTINUE WITH THE FIRST LABEL.|cobolfree}} There was also the alternative form {{code|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 {{code|CONTINUE FROM THE BEGINNING.|cobolfree}} "As follows" could be used to refer to the next statement, {{code|CONTINUE AS FOLLOWS.|cobolfree}}, which could be used to clarify branches.{{sfn|Barnett|1970|p=230}}
Conditional branches used an if–then(–else) structure:
{{sxhl| IF J IS LESS THAN 80 INCREASE J BY 1, AND REPEAT FROM THE FIRST LABEL, OTHERWISE CONTINUE AS FOLLOWS.|cobolfree}}
As in most languages, the {{code|OTHERWISE}} section was optional. Note the use of {{code|AND}} to make a compound statement within the then section, offering a block structure. For string comparisons, one used {{code|IS}} or the optional {{code|IS THE SAME AS|cobolfree}}.{{sfn|Barnett|1970|p=232}}
SNAP included a number of other keywords that had no behaviour of their own that were added simply for syntactic sugar. Among them were {{code|THE}}, {{code|A}}, {{code|FROM}} which the programmer could add in many locations to make the syntax more readable. Typical uses included {{code|READ A RECORD|cobolfree}} and {{code|REPEAT FROM THE LOOP START|cobolfree}}.{{sfn|Barnett|1970|p=230}}
=Statements=
From A Natural Language.{{sfn|Barnett|Ruhsam|1968|p=48}} 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
:
::jump to the named label, the start of the program, or continue on to the next statement
:IF value|string
::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 ]
::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 SELECT
ed 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 SELECT
ed device
Others:
:CONTROL various
::a temporary command used to control the language as new features were added
:RESERVE SPACE FOR number
::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,{{sfn|Barnett|1970|p=229}} which reads strings from cards and then prints out the individual words found in them:
{{sxhl|
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
|cobolfree}}
For clarity, the following version simply spaces out the statements onto separate lines and adds appropriate whitespace:
{{sxhl|
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
|cobolfree}}
The program {{code|READ}}s a single card and assigns the string data found on it to the variable named {{code|RECORD}}. It then sets up two pointers, {{code|I}} and {{code|J}}. A function called {{code|KEY}} is {{code|CALL}}ed that returns the Jth character of {{code|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 {{code|OUTPUT ACTION}}.
If it does find a word-breaking character, it jumps to {{code|BACKUP}}, which backs up one character to skip the punctuation it just examined. It then naturally falls through to the {{code|OUTPUT ACTION}}. That code prints out the string between the starting position in {{code|I}} to the current position in {{code|J}}.
If we have not reached the end of the card, move {{code|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 {{code|I}} to {{code|J}} to position our next word's starting position from this point, and return to {{code|LOOP START}}. If we are at the end of the card, start the entire program over and read another card.
Notes
{{notelist}}
References
=Citations=
{{reflist}}
=Bibliography=
- {{cite conference
|title=SNAP: an experiment in natural language programming
|first1=Michael |last1=Barnett
|first2=William |last2=Ruhsam
|editor=Harrison Fuller
|conference=AFIPS '69, Spring Joint Conference
|location=Boston
|date=May 1969
|pages=75–87
|url=https://dl.acm.org/citation.cfm?id=1476815&dl=ACM&coll=DL
|doi=10.1145/1476793.1476815
|url-access=subscription
}}
- {{cite journal
|title=A Natural Language Programming System for Text Processing
|first1=Michael |last1=Barnett
|first2=William |last2=Ruhsam
|journal=IEEE Transactions on Engineering Writing and Speech
|pages=45–52
|volume=11 |number=2
|date=August 1968
|doi=10.1109/TEWS.1968.4322334
|jstor=30199362 |s2cid=51670564 }}
- {{cite journal
|title=SNAP: A Programming Language for Humanists
|first=Michael |last=Barnett
|journal= Computers and the Humanities
|pages= 225–240
|volume= 4|date=March 1970
|issue=4 |doi=10.1007/BF02404375 |jstor=30199362}}
=Further reading=
- {{cite book
|title=Computer Programming in English
|url=https://archive.org/details/computerprogramm00barn
|url-access=registration
|first=Michael |last=Barnett
|publisher=Harcourt, Brace & World
|date=1969
|ol=5754250M }}