The icon programming language (Prentice - Hall, 1983)
Icon is a high-level,general - purpose progrmaming languaje that contains many features for processing nonnumeric data, particulary for textual material consinting of strings of characters. Icon was designed to aid in analyz-ing natural languajes, reformatting data, transforming computer programs. generating computer programs, generating computer programs, manipulating formulas, formatting documents, and so forth. It is suited to situations where a quick solution is needed, one that can be obtained with a minium of time and programing efforts such as computer-generated poetry, in which a proposed problem solution is more heuristic than algorithmic. It also excels for very complacited problems. In its focus on solutions for nonnmurerical problems, Icon continues the tradition of SNOBOL4 [1]. However, Icon has modern control structures, and its facilities for string analysis and synthesis are more extensive than those of SNOBOL4. White string analysis and synthesis, together with goal-directed evaluation, are just a part of the pattern-maching mechanism in SNOBO4, these features are an integral part of Icon, making possible a wide variety of programming techniques. There are several general characteristics of Icon that contribute to its "personality". It is an expression- based languaje with a syntax similar to Algol 68 [2] and Pascal [3]. Icon has many of the traditional control structures that are found in other programing languajes, but it lacks labels and go-tos. Superficially, Icon programs resemble those in many other moderm programing languajes. In Icon, strings of characters are valvues in their own right, as opposed to being treated as arrays of characters. Strings may be arbitrarily long, althoug there are both practical considerations and pysical limitations. Icon has neither storage declarations nor explicit allocation and deallocation operations; management of storage for strings and other values is handled automatically. There are no type declarations in Icon; it is an "untyped" languaje in which a variable may have values of different types during program excution. Type conversion is automatic. For example, a numeric value read into a program as a string is converted automatically to a number if it is used in a numerical operation. Error cheking is rigorous ; a value that cannot be converted to a requiered type in a meanningful way causes termination of program execution with a diagnostic message. Like SNOBOL4, but unlike most other programing languajes, operations in Icon may succeed or fail. Algol - like programing languajes have conditional operations ( such as the comparison of the magnitudes of integers) that produce Boolean values true or falase depending on whether or not a condition is satisfied. A control structure ( such as the comparison of the magnitudes of integers) that produce Boolean values true or false depending on wheter or not a condition is satisfied. A control structure such as if i ‹ j then expr is"driven" by the Boolean value produced by the expression i ‹ j. Therefore, if the value of i is less than the value of j, i ‹ j produces true and expr and is evalued. if i is not less than j,i ‹ produces false and expr and is evalued. Icon has a control structure is driven by the success or failure of i ‹ j. The distinction is not just a matter of terminology but goes to the heart of the lenguaje. Consider the Icon funcition find(s1,s2), which produces the position at which s1 occurs as a subrstring of s2. Depending on the values of s1 and s2, there may or not be such a posittion. If there is such a position, it is produced as the value of find, while if there is not such a positions, It there is such a position, it is produced as the value of find, while if there is not such a position. Find fails. this allows find to be used both in the control clause of a control structure such as an if-then -else expression and in control clause of a control structure such as if-then-else expresdion and in ordinary computational contexts where its value is useful. This use of success and failure contrasts with languajes like PL/ I [4], in which the function INDEX produces zero if s1 is not a substring of s2. A test for a zero value can be made, of course, but this cumbersome. Another example of the usefulness of produccing a meaningful value when a conditional operation succeeds occurs in comparison operations. A comparison operation produces the value of its right argument if it succeeds. Therefore, i ‹ j produces the value of j if the comparison succeeds. Consequently, i ‹ j ‹ k which groups as (i ‹ j) ‹ k succeeds if the value of j is between the values of i and k. In many programing languajes, such a construction is either errneous or meanningless. One of the more unusual features of Icon is its concept of generators, expressiones that may produce more than one value. The function find, described previsiously, illustrates the posibilities. Consider, for example, find ("th","this thesis is the best one") Here th occurs at three positions in the second argument:1,6, and 16. In most programming languajes, such a situation is resolved by selecting one position for the value of the function ( the first position is most often the rule ). This interpretation discards potentially useful informatión, however. Icon generalizes the concept of expression evalution to allow an expression to produce more than one result. These results are produced in sequence as determined by context. One context is the iteration control structure every expr1 do expr2 which evalutues expr for every result produced by expr. An example is every i:= finds (s1,s2 ) do write (i) which writes all the positions at which s1 occurs as a substring of s2. It is worth noting here that a numbers of other programming languajes have constructions called genrators. CLU [5] is an example. In most languajes, however, genrators are confined to particular operations on certain kinds of values. In Icon, generators are completely general and may occurian any computatión. Gnerators in themselves lend connciseness and expressive power. Perhaps the most significant aspect of Icon is goal-directed evaluation. This term suggests that the evaluation of expressions is purposeful, as it in pattern matching in SNOBOL4. Here the purpose is to achieve success for expression evaluation, that is, some result. In most programming languages, such a concept is meanningless; all expressions produce a result ( but not necesarily a computationally useful one). The usefulness of goal- directed evaluations in Icon comes from the capability of generators to produce more than a single result, Consider, for example, if finds (s1,S2)= 10 then expr1 else expr2 The intuitive meaning of this expressión is: "If s1 occurs as subrstring of s2 at a position that is equal to 10, then evaluate exp1: otherwise evaluate expr2" This is, in fact, exactly waht this expression does in Icon. Furthermore, this works even if s1 also occurs at positions less than 10 or greater than 10. Without generators, it is necessary to look through succesive substrings.Neither generators nor goal - direct evaluation depends on any particular feature for processing strings; find is useful pedagogically, but there are many possibilities in numerical compution. Furthermore, Icon allows programmers to write their own generators, and there is no limit to the range of their applicability. Since Icon is oriented toward the processing of textual data, it has a large repertoire of functions for operating on string, of which find is only one example. Icon also has high-level string scanning facilty. String scanning, like pattern matching in SNOBOL4. Unlike pattern matching in SNOBO4, string scanning is integrated in to the