Paradigm | multi-paradigm: structured, text-oriented |
---|---|
Designed by | Ralph Griswold |
First appeared | 1977 |
Stable release |
9.5.1 / June 6, 2013
|
Typing discipline | dynamic |
Website | www |
Major implementations | |
Icon, Jcon | |
Dialects | |
Unicon | |
Influenced by | |
SNOBOL, SL5, ALGOL | |
Influenced | |
Unicon, Python, Goaldi |
Icon is a very high-level programming language featuring goal-directed execution and many facilities for managing strings and textual patterns. It is related to SNOBOL and SL5, string processing languages. Icon is not object-oriented, but an object-oriented extension called Idol was developed in 1996 which eventually became Unicon.
The Icon language is derived from the ALGOL-class of structured programming languages, and thus has syntax similar to C or Pascal. Icon is most similar to Pascal, using :=
syntax for assignments, the procedure
keyword and similar syntax. On the other hand, Icon uses C-style brackets for structuring execution groups, and programs start by running a procedure called "main".
In many ways Icon also shares features with most scripting languages (as well as SNOBOL and SL5, from which they were taken): variables do not have to be declared, types are cast automatically, and numbers can be converted to strings and back automatically. Another feature common to many scripting languages, but not all, is the lack of a line-ending character; in Icon, lines not ended by a semicolon get ended by an implied semicolon if it makes sense.
Procedures are the basic building blocks of Icon programs. Although they use Pascal naming, they work more like C functions and can return values; there is no function
keyword in Icon.
One of Icon's key concepts is that control structures are based on the "success" or "failure" of expressions, rather than on boolean logic, as in most other programming languages. Under this model, simple comparisons like if a < b
do not mean "if the operations to the right evaluate to true" as they would under most languages; instead it means something more like "if the operations to the right succeed". In this case the < operator succeeds if the comparison is true, so the end result is the same. In addition, the < operator returns its second argument if it succeeds, allowing things like if a < b < c
, a common type of comparison that in most languages must be written as a conjunction of two inequalities like if a < b && b < c
.