G/EDANKEN&Mdash;A Simple Typeless Language Based on the Principle of Completeness and the Reference Concept
Total Page:16
File Type:pdf, Size:1020Kb
GEDANKEN-A Simple Typeless context of the language is permissible in any other mean- ingful context. In particular, functions and labels are per- Language Based on the mitted to be results of functions or values of references (e.g. variables), without imposing restrictions which main- Principle of Completeness and the tain a stack discipline for run-time storage allocation. (2) The Reference Concept. Assignment and indirect Reference Concept addressing are formalized in the following manner: among the possible values which may occur in a program are objects called references, which in turn possess other values. JOHN C. REYNOLDS The assignment operation always affects the relation be- Argonne National Laboratory,* Argonne, Illinois tween some reference and its value. Neither of these principles is novel. LISP [la and lb] (in its interpretive implementations), IswIM [2], and PAL GEDANKEN is an experimental programming language with the [3] all satisfy the principle of completeness, and the refer- following characteristics. (1) Any value which is permitted in ence concept is used in ALGOL 68 [4] and BASEL [5]. But some context of the language is permissible in any other mean- GEDANKEN goes beyond these languages in exploiting the ingful context. In particular, functions and labels are permissible power of these principles, i.e. in eliminating other language results of functions and values of variables. (2) Assignment and features which are rendered redundant by completeness indirect addressing are formalized by introducing values, and references. SpecificMly: called references, which in turn possess other values. The as- (1) The existence of function-returning and reference- signment operation always affects the relation between some returning functions allows all compound data structures to reference and its value. (3) All compound data structures are be treated as functions. For example, a one-dimensional treated as functions. (4) Type declarations are not permitted. ALGoL-like array is treated as a function whose domain is a The functional approach to data structures and the use of finite set of consecutive integers and which maps each of references insure that any process which accepts some data these integers into a unique reference. This approach in- structure will accept any logically equivalent structure, regard- sures that any process which accepts some data structure less of its internal representation. More generally, any data will accept any logically equivalent structure, regardless of structure may be implicit; i.e. it may be specified by giving an its internal representation. More generally, any data struc- arbitrary algorithm for computing or accessing its components. ture may be implicit; i.e. it may be specified by giving an The existence of label variables permits the construction of co- arbitrary algorithm for computing or accessing its compo- routines, quasi-parallel processes, and other unorthodox control nents. (Functional data structures have been suggested by mechanisms. Balzer [6], but his realization of the concept is quite differ- A variety of programming examples illustrates the generality ent than GEDANKEN.) of the language. Limitations and possible extensions are dis- (2) The existence of label variables permits the construc- cussed briefly. tion of coroutines, quasi-parallel processes, and other un- KEY WORDS AND PHRASES: programming language, data structure, refer- orthodox control mechanisms. This is a direct consequence ence, assignment, coroutine, quasi-parallel process, typeless language, applica- of not imposing a stack discipline on the program control tive language, lambda calculus, list processing, nondetermlnlstlc algorithm information. CR CATEGORIES: 4.20, 4.22, 5.23, 5.24 The main limitation of GEDANKEN is that declara- tions are not allowed to restrict the value ranges of identi- fiers, references, or function results. Languages with this Introduction property are usually called "typeless," although the types The recent development of programming languages of values may be tested during execution. We do not sug- suggests that the simultaneous achievement of simplicity gest that type declarations are unimportant or that it is and generality in language design is a serious unsolved trivial to add them to GEDANKEN without destroying problem. This paper describes an experimental language, the generality of the language; this is a major theoretical called GEDANKEN, which was developed to attack this problem. problem. The originality of GEDANKEN lies primarily in the GEDANKEN is not intended to be a generally useful language features which have been excluded, and the main language, althoughit could be effective in situations where a aim of this paper is to demonstrate that these exclusions fair degree of object program inefficiency is tolerable. Its (except typelessness) do not impair generality. For this major purpose (reflected in its name, which is meant as an purpose, we include extensive programming examples. analogy to gedankenexperiments in physics) is to explore A formal definition of GEDANKEN is given in [7]. A the consequences of two basic design principles: complete but extremely inefficient implementation has (1) Completeness. Any value which is permitted in some been produced by translating this formal definition into * Applied Mathematics Division. Work performed under the LisP; this implementation has been used to check all auspices of the US Atomic Energy Commission. examples given in this paper. 308 Communications of the ACM Volume 13 / Number 5 / May, 1970 After describing the syntax of the language and the types TABLE I. A GRAMMAI¢ FOR GEDANKEN of values which are manipulated during program execution, we discuss the applicative part of the language, i.e. the (expo) ::= (constant> [ (identifier) I ((block)) (expl) ::= (expo) ] (function designator> evaluation of expressions and the application of functions. (function designator) ::= (expc> (expl) Finally, the imperative aspects, such as references, assign- (exp2) ::= (expl) [ (expl) = (exp2) ment, labels, and jumps, will be introduced. (expa) ::= (exp2) ] (exp2) AND (exp,) (exp4) ::= (exp3) ] (exp3> OR (exp4) Syntax (exp.> ::= (exp4) ] (conditional exp) [ (lambda exp>[ (exp4) := (exps) (conditional exp) ::= IF (exp6) THEN (exps) ELSE (exps) Mthough the importance of GEDANKEN lies in its (lambda exp) ::= k (pform0) (exp,) semantics, a definite syntax must be specified so that pro- (exp6) ::= (exps) I (sequence exp) ] (case exp) gramming examples can be given. A GEDANKEN program (sequence exp) ::= (empty> [ (exp,), (exps> {, (exp6>}* is a sequence of tokens separated by zero or more blanks, (case exp) ::= CASE (exp6) OF (exp6) {, (exps)}* (pform¢> ::= (identifier) [ ((pforml)) with at least one blank used as a separator whenever the (pforml) ::= (pform6) [ (sequence pform) juxtaposition would otherwise be ambiguous. The tokens (sequence pform) ::= (empty> ] (pform¢), (pform0) [, (pform0)}* are sequences of characters classified as follows: (decl) ::= (pforml> IS (exp6) (recursive decl) ::= (identifier> ISR (lambda exp) constants digit strings (denoting integers), quoted strings (label> ::= (identifier> : reserved words AND, OR, IF, THEN, ELSE, CASE, OF, (statement> ::= {(label>}* (exp6) IS, ISR (block) :: = {(decl);}* {(recursive decl); }* {(statement>; }* identifiers all other alphanumeric strings beginning with (statement> a letter (program> ::= (block) punctuation tokens k, = : () ; := Certain predefined identifiers have standard meanings. These include: TRUE, FALSE, LL, and UL, which denote they are similar to atoms in LisP, except that they lack specific primitive values; ERROR, which denotes a built-in property lists and print names, l~Iore precisely, the atoms label value causing program termination; and the names of are a denumerably infinite set of values which may be all built-in functions. (These predefined identifiers differ tested for equality, but which do not possess any ordering from reserved words in that the programmer can override or arithmetic operations. Two particular atoms, denoted the standard meanings by declarations.) by the predefined identifiers LL and UL, play a special role The set of token sequences which are well-formed in the language. Additional atoms are created by the GEDANKEN programs is specified by the context-free built-in function ATOM, which returns a distinct atom grammar (over an infinite vocabulary of tokens) in Table each time it is applied. I. The syntactic variables in this grammar are subscripted A function is a value which may be applied to another to distinguish among phrases with a similar semantic role value called its argument. When so applied, the function but different levels of precedence. Thus phrases of the will either: (i) return a value called its result, (ii) transfer classes (exp0), ... , (exps) are all called expressions, while control to a label value without returning a result, (iii) phrases of the classes (pform0) and (pform~) are called cause an error stop, or (iv) initiate a nonterminating com- parameter forms. The notation {a} * is used to indicate an putation. (The application of a function may also alter the arbitrary number (including zero) of occurrences of the state of a computation by producing various side effects, string a. which will be discussed later.) The set of arguments for It should be noted that a block can consist of a single which a function will return a result is called the domain expression; this permits any expression to be parenthesized