| 1 |
|
| 2 |
#here's cat in icon (line by line): |
| 3 |
|
| 4 |
procedure main() |
| 5 |
while write(read()) #fails when eof |
| 6 |
end |
| 7 |
|
| 8 |
#here's writing out the command line arguments |
| 9 |
|
| 10 |
procedure main(arg) #passed a list of strings |
| 11 |
every write( !arg) # ! (bang) makes a generator sequence |
| 12 |
end |
| 13 |
|
| 14 |
#here's finding all lines in standard input containing "frog" |
| 15 |
|
| 16 |
procedure main() |
| 17 |
while line := read() do line ? #string matching subject is line |
| 18 |
if find("frog") then write(line) |
| 19 |
end |
| 20 |
|
| 21 |
#here's finding the text on each line that contains "frog" that |
| 22 |
#lies before the first occurrence of "frog" |
| 23 |
|
| 24 |
procedure main() |
| 25 |
while line := read() do line ? #string matching subject is line |
| 26 |
write( tab(find("frog")) ) |
| 27 |
end |
| 28 |
|
| 29 |
#here's generating the first 1000 squares |
| 30 |
|
| 31 |
procedure main() |
| 32 |
every write( squares() ) \1000 #truncate generator to 1000 results |
| 33 |
end |
| 34 |
|
| 35 |
procedure squares() |
| 36 |
n := 0 |
| 37 |
repeat { |
| 38 |
n +:= 1 |
| 39 |
suspend n^2 #shoot out next element of generator sequence |
| 40 |
} |
| 41 |
end |
| 42 |
|
| 43 |
procedure main() |
| 44 |
(n := 1) | |( n +:= 1, n^2 ) |
| 45 |
end |
| 46 |
|
| 47 |
#So that |
| 48 |
procedure main() |
| 49 |
every write( (n := 1) | |( n +:= 1, n^2 ) ) \1000 |
| 50 |
end |