Icon Online Compiler
Icon is a language most programmers haven't heard of, which is a shame because its ideas are genuinely interesting. Developed by Ralph Griswold in the late 1970s, Icon introduced goal-directed evaluation -- expressions can succeed or fail, and failure drives control flow automatically. It also has generators, which produce sequences of values on demand, years before Python popularized the concept.
String processing was Icon's original strength. Its string scanning facility lets you walk through strings with pattern matching in a way that feels more natural than regular expressions for certain tasks.
Why try Icon in the browser?
Icon isn't in most package managers. Getting it running locally means finding the right binary or building from source. An online compiler makes it simple to experiment with Icon's unique features without any installation.
Generators and string scanning
procedure main()
# Generators: every drives a generator to produce all values
write("Squares from 1 to 5:")
every i := 1 to 5 do
write(" ", i, "^2 = ", i * i)
# String scanning
text := "The Icon language was created in 1977"
write("\nWords in: ", text)
text ? {
while tab(upto(&letters)) do {
word := tab(many(&letters))
write(" Found word: ", word)
}
}
# Alternation operator generates multiple values
write("\nVowels found:")
every c := !"aeiou" do {
if find(c, text) then
write(" '", c, "' appears in the text")
}
end
The every keyword is what makes Icon tick. Where most languages would use a loop with an explicit iterator, every drives a generator expression and executes the body for each value it produces. The ? operator starts string scanning on a subject string, and functions like upto and tab navigate through it. If a match fails, Icon backtracks automatically.
Running Icon on OneCompiler
OneCompiler supports Icon and shows you the output immediately. It's probably the easiest way to get a feel for goal-directed evaluation and generators if you've never encountered them outside of Python. The concepts are worth learning even if you never write production Icon code.
Try Icon here: Icon Online Compiler on OneCompiler