PLACE
languages
RPN in ABC

ABC

ABC is best known, if at all, for the major influence that it had in the formation of Python – now a much more popular programming language. However, ABC predates Python by many years, was created with a different purpose, and is much simpler. It was itself influenced by SETL, and possibly also by other languages (APL?, Logo?).

The language emerged in about 1975, initially under the name B (coincidentally the same as the name of the C’s predecessor). It was intended as a replacement for BASIC as a teaching language and environment – one that would retain the ease of learning and using BASIC but is rather different in nature: much more expressive, and accompanied by a helpful programming environment.

Concepts and Constructs

ABC has a very small number of concepts. There are five datatypes: numbers, texts (strings), lists, tables (finite mappings), and compounds (tuples). Numbers that are not floating-point are exact: integers are of unbound magnitude and fractions have arbitrary precision. Lists' contents are implicitly kept sorted, and similarly, tables are sorted – wherever it makes sense to sort the contents of a table – on their key sets. A compound is always explicitly constructed (by enumerating its elements) and deconstructed; there are no constructors, selectors, or modifiers for compounds.

There is no Boolean type as such, but built-in and programmer-defined predicates can be used within commands such as IF and SELECT for control sequencing.

ABC provides no means to create user-specific datatypes, but the built-in ones have a wide range of uses, rendering the said restriction much less significant than it may seem at first.

ABC is dynamically typed, neither needing nor allowing type declarations. Unlike other dynamically typed languages, ABC is also strongly typed. This includes lists and tables being homogeneous: all items in a list or in a table must be of the same type; the keys in a table must be of a single type, too.

All executable entities, predefined as well as programmer-defined, are of three kinds: commands, functions, and predicates. Commands do not return values; functions and predicates do. Functions and predicates are each restricted to having either of zero, one or two arguments. Two-argument ones are infix. A single name can designate both a monadic and a dyadic function or predicate, e.g. root x is the square root of x, while n root x is the n-th root. Functions and predicates can be polymorphic, e.g. the same function, denoted #, is used to obtain the number of elements in a string, list, or table. Functions and predicates are not allowed to side-effect.

User-defined sub-programs are called how-to's, and slightly different syntax is used to define a how-to of a command, function, or predicate kind.

Similar to functions, predicates can form expressions. Predicate expressions are built up using logical connectors such as AND and OR. Unlike all other expressions, those of the predicate kind have no immediately observable values – ones that can be stored, copied, passed as arguments, etc. Instead, the only use predicate expressions ultimately have is as conditions within the control sequencing commands.

A specific variety of predicate expressions are the quantified tests of existential and universal kinds, which can bind names to values based on searching items within aggregate values which satisfy (or not) certain conditions. An example is SOME…IN…HAS… – аn existentially quantified test. The said bindings become accessible in the surrounding environment, which makes quantified tests particularly attractive. These constructs have apparently been borrowed from SETL, but, alas, in ABC they are not as useful; the binding that results from a quantified test occurs only once, so applying a test in a repetitive context does not make sense.

Along with the how-to's, there are the so called refinements – again, a concept that must have been borrowed from SETL. Like how-to's, refinements come in three possible varieties, command, function, and predicate, but have no parameters.

Syntax

Statement nesting is expressed through indentation – just like in the more recent Python, Miranda, Haskell, and occam. Another characteristic feature of the ABC's syntax is the use of capital and small letters to distinguish between names of two different roles in the language: keywords are written in capital letters and designate commands, while all other names are written in small letters. One should take into account that the term keyword has a broader meaning in ABC, including not only predefined names but also programmer-defined ones.

ABC being an imperative language, commands are its most important construct. A distinctive feature of ABC with respect to commands is making possible a certain degree of syntactic freedom in specifying them: any sequence of keywords and arguments that starts with a keyword can be a command. This feature can be used to improve a program text's readability (at the expence of introducing verbosity) by imitating phrases in a natural language. Note that this gives user-defined commands the syntactic appearance of the built-in ones, such as PUT…IN…, FOR…IN…, and HOW TO…. The following program defines a command and calls it twice:

HOW TO ADD one TO another TO GET A mix:
  PUT another, one IN mix

ADD 'vermouth' TO 'gin' TO GET A martini
WRITE martini /
ADD 'water' TO 'gravel', 'sand', 'cement' TO GET A concrete
WRITE concrete /

Executing the program produces this output:

("gin", "vermouth")
(("gravel", "sand", "cement"), "water")

Programming Environment

There is a small number of commands, functions and predicates predefined in the language. Some of them are polymorphic. An example of a group of polymorphic functions is one that is related to trains. The latter is a convenience term, denoting at once ABC's strings, lists, and tables with respect to the properties that they have in common. (The above mentioned # is an operation on trains.)

ABC is interpreted and interactive: within the interpreter, one can execute single commands, explore the contents of variables and sub-programs, and change them. The so called ABC programming environment (PE) that goes together with the language is an interpreter with a language-aware editing and support for workspaces built-in in it. ‘Language-aware editing’ means that user's input is syntax-directed (structure-based). As the user enters text to be interpreted, the PE tries to recognize a command or another construct, and suggests a continuation, with ‘slots’ to be filled in with specific data. Suggestions are dynamic: typing a text that does not conform to the currently provided suggestion automatically leads to changing the latter. The suggestion mechanism includes changing the letter case and indenting for the user where applicable. Copying, moving, and removal of text is also supported in a language-aware, structure-based manner.

The ABC PE prevents from entering syntactically wrong constructs – a rare feature among language-oriented programming environments.

Workspaces is where program's main constituting entities – global variables and how-to's – are stored. There is a current workspace at any time. Switching to another workspace changes the working context. There is a central workspace who's how-to's are accessible to all other workspaces.

Storing to the current workspace takes place automatically, so all data is persistent: values map to files, and workspaces – to directories in the host operating system. Persistency is considered a substitute for file input/output operations which are absent in ABC.

Links of Relevance

Home page of ABC. There are a lot of documents there just repeating each other's content. I've found the following two to cover pretty much everything:
Issue 7 (Aug 1995) of The ABC Newsletter: a quick reference for the language and its environment, small and larger program examples, and other things
Selected examples: see esp. the implementation of the famous Eliza

boykobbatgmaildotcom