SNAP (programming language)

Last updated
SNAP
Paradigm Imperative
Designed by Michael Barnett, William Ruhsam
First appeared1970;53 years ago (1970)

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.

Contents

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 parentheses 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, SETITO1.SET was also used to perform mathematical operations, like SETITOTHEPRODUCTOF10 ANDJ. 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, CALLTHEJ-THCHARACTEROFNEWSTRINGTHENEWCHAR., or CALLTHEM-THTHROUGHN-THCHARACTERSOFTHEINPUTTHEOUTPUT. [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 READTHECARDLIST., 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 PRINTTHE5-THCARD, or COPY "NEW STRING"ANDCALLITTHE7-THCARD. Lists of numbers could be created using SETTHENUMBERLISTTO1,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"THE1-STPART.CALL "WORLD"THE2-NDPART. 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, SETJTO1.PRINTKEY.INCREASEJBY1.PRINTKEY. 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 COPYOLDSTRING,ANDCALLITNEWSTRING. 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, CONTINUEWITHTHEFIRSTLABEL. 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 CONTINUEFROMTHEBEGINNING. "As follows" could be used to refer to the next statement, CONTINUEASFOLLOWS., which could be used to clarify branches. [13]

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

IFJISLESSTHAN80 INCREASEJBY1,ANDREPEATFROMTHEFIRSTLABEL,OTHERWISECONTINUEASFOLLOWS.

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 ISTHESAMEAS. [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 READARECORD and REPEATFROMTHELOOPSTART. [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|stringexpression[,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:

READARECORD.SETITO1.SETJTO1.CALLTHEJ-THCHARACTEROFTHERECORDTHEKEY.(LOOPSTART)IFTHEKEYIS " "CONTINUEWITHTHEBACKUP.IFTHEKEYIS ""CONTINUEWITHTHEBACKUP.IFTHEKEYIS "."CONTINUEWITHTHEBACKUP.IFJISLESSTHAN80 INCREASEJBY1,ANDREPEATFROMTHELOOPSTART,OTHERWISECONTINUEWITHTHEOUTPUTACTION.(BACKUP)DECREASEJBY1.(OUTPUTACTION)PRINTTHEI-THTHROUGHJ-THCHARACTERSOFTHERECORD.IFJISLESSTHAN79 INCREASEJBY2,SETITOJ,ANDREPEATFROMTHELOOPSTART,OTHERWISEREPEATFROMTHEBEGINNING.EXECUTE

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

READARECORD.SETITO1.SETJTO1.CALLTHEJ-THCHARACTEROFTHERECORDTHEKEY.(LOOPSTART)IFTHEKEYIS " "CONTINUEWITHTHEBACKUP.IFTHEKEYIS ""CONTINUEWITHTHEBACKUP.IFTHEKEYIS "."CONTINUEWITHTHEBACKUP.IFJISLESSTHAN80 INCREASEJBY1,ANDREPEATFROMTHELOOPSTART,OTHERWISECONTINUEWITHTHEOUTPUTACTION.(BACKUP)DECREASEJBY1.(OUTPUTACTION)PRINTTHEI-THTHROUGHJ-THCHARACTERSOFTHERECORD.IFJISLESSTHAN79 INCREASEJBY2,SETITOJ,ANDREPEATFROMTHELOOPSTART,OTHERWISEREPEATFROMTHEBEGINNING.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.

Related Research Articles

<span class="mw-page-title-main">AWK</span> Programming language

AWK is a domain-specific language designed for text processing and typically used as a data extraction and reporting tool. Like sed and grep, it is a filter, and is a standard feature of most Unix-like operating systems.

Icon is a very high-level programming language based on the concept of "goal-directed execution" in which code returns a "success" along with valid values, or a "failure", indicating that there is no valid data to return. The success and failure of a given block of code is used to direct further processing, whereas conventional languages would typically use boolean logic written by the programmer to achieve the same ends. Because the logic for basic control structures is often implicit in Icon, common tasks can be completed with less explicit code.

In computer science, control flow is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an imperative programming language from a declarative programming language.

Programmed Inquiry, Learning, or Teaching (PILOT) is a simple high-level programming language developed in the 1960s. Like its younger sibling LOGO, it was an early foray into the technology of computer-assisted instruction.

HyperTalk is a discontinued high-level, procedural programming language created in 1987 by Dan Winkler and used in conjunction with Apple Computer's HyperCard hypermedia program by Bill Atkinson. Because the main target audience of HyperTalk was beginning programmers, HyperTalk programmers were usually called "authors" and the process of writing programs was known as "scripting". HyperTalk scripts resembled written English and used a logical structure similar to that of the Pascal programming language.

<span class="mw-page-title-main">C shell</span> Unix shell

The C shell is a Unix shell created by Bill Joy while he was a graduate student at University of California, Berkeley in the late 1970s. It has been widely distributed, beginning with the 2BSD release of the Berkeley Software Distribution (BSD) which Joy first distributed in 1978. Other early contributors to the ideas or the code were Michael Ubell, Eric Allman, Mike O'Brien and Jim Kulp.

<span class="mw-page-title-main">C syntax</span> Set of rules defining correctly structured programs

The syntax of the C programming language is the set of rules governing writing of software in the C language. It is designed to allow for programs that are extremely terse, have a close relationship with the resulting object code, and yet provide relatively high-level data abstraction. C was the first widely successful high-level language for portable operating-system development.

<span class="mw-page-title-main">For loop</span> Control flow statement for repeated execution

In computer science a for-loop or for loop is a control flow statement for specifying iteration. Specifically, a for loop functions by running a section of code repeatedly until a certain condition has been satisfied.

TI-BASIC is the official name of a BASIC-like language built into Texas Instruments (TI)'s graphing calculators. TI-BASIC is a language family of three different and incompatible versions, released on different products:

<span class="mw-page-title-main">Java syntax</span> Set of rules defining correctly structured program

The syntax of Java is the set of rules defining how a Java program is written and interpreted.

Color BASIC is the implementation of Microsoft BASIC that is included in the ROM of the Tandy/Radio Shack TRS-80 Color Computers manufactured between 1980 and 1991. BASIC is a high level language with simple syntax that makes it easy to write simple programs. Color BASIC is interpreted, that is, decoded as it is run.

In programming languages, a label is a sequence of characters that identifies a location within source code. In most languages, labels take the form of an identifier, often followed by a punctuation character. In many high-level languages, the purpose of a label is to act as the destination of a GOTO statement. In assembly language, labels can be used anywhere an address can. Also in Pascal and its derived variations. Some languages, such as Fortran and BASIC, support numeric labels. Labels are also used to identify an entry point into a compiled sequence of statements.

The structure of the Perl programming language encompasses both the syntactical rules of the language and the general ways in which programs are organized. Perl's design philosophy is expressed in the commonly cited motto "there's more than one way to do it". As a multi-paradigm, dynamically typed language, Perl allows a great degree of flexibility in program design. Perl also encourages modularization; this has been attributed to the component-based design structure of its Unix roots, and is responsible for the size of the CPAN archive, a community-maintained repository of more than 100,000 modules.

PL/SQL is Oracle Corporation's procedural extension for SQL and the Oracle relational database. PL/SQL is available in Oracle Database, Times Ten in-memory database, and IBM Db2. Oracle Corporation usually extends PL/SQL functionality with each successive release of the Oracle Database.

<span class="mw-page-title-main">TI-BASIC 83</span> Calculator programming language

TI-BASIC 83,TI-BASIC Z80 or simply TI-BASIC, is the built-in programming language for the Texas Instruments programmable calculators in the TI-83 series. Calculators that implement TI-BASIC have a built in editor for writing programs. While the considerably faster Z80 assembly language is supported for the calculators, TI-BASIC's in-calculator editor and more user friendly syntax make it easier to use. TI-BASIC is interpreted.

Data General Extended BASIC, also widely known as Nova Extended BASIC, was a BASIC programming language interpreter for the Data General Nova series minicomputers. It was based on the seminal Dartmouth BASIC, including the Fifth Edition's string variables and powerful MAT commands for matrix manipulation. In contrast to the compile-and-go Dartmouth BASIC, Extended BASIC was an interpreter.

SDS BASIC, also known as CP-V BASIC, Batch BASIC or Sigma BASIC depending on the version, is a BASIC programming language compiler for Scientific Data Systems's (SDS) Sigma series mainframe computers, originally released in 1967. Xerox purchased SDS in 1969 and began rebranding it as Xerox Data Systems, and finally just Xerox, at which time the language became known as Xerox BASIC.

Wang BASIC is a series of BASIC programming languages for computers from Wang Laboratories. The term can be used to refer to the BASIC on any Wang machine, but is mostly associated with the versions on the Wang 2200 minicomputer series of the early 1970s. When these machines were updated to the VP series in 1976, BASIC-2 was introduced and remained the pattern for future machines in the 2200 series. A planned BASIC-3 was never released.

The Hack Computer is a theoretical computer design created by Noam Nisan and Shimon Schocken and described in their book, The Elements of Computing Systems: Building a Modern Computer from First Principles.  In using the term “modern”, the authors refer to a digital, binary machine that is patterned according to the von Neumann architecture model.

Acorn System BASIC and Atom BASIC are two closely related dialects of the BASIC programming language developed by Acorn Computers for their early microcomputers like the Acorn System 3 and Acorn Atom. Developed in-house, they have a number of significant idiosyncrasies compared to most BASIC dialects of the home computer era.

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. 1 2 3 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. 1 2 3 4 Barnett 1970, p. 228.
  10. Barnett & Ruhsam 1968, p. 49.
  11. Barnett 1970, p. 231.
  12. 1 2 Barnett 1970, p. 232.
  13. 1 2 Barnett 1970, p. 230.
  14. Barnett 1970, p. 229.

Bibliography

Further reading