summaryrefslogtreecommitdiff
path: root/ipl/packs/loadfuncpp/examples/carl.icn
blob: 2d7c6a40cb5e5f29f2cb358008fdc0d9dc87ae78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50

#here's cat in icon (line by line):

procedure main()
     while write(read()) #fails when eof
end

#here's writing out the command line arguments

procedure main(arg)  #passed a list of strings
     every write( !arg)  # ! (bang) makes a generator sequence
end

#here's finding all lines in standard input containing "frog"

procedure main()
     while line := read() do line ? #string matching subject is line
         if find("frog") then write(line)
end

#here's finding the text on each line that contains "frog" that
#lies before the first occurrence of "frog"

procedure main()
     while line := read() do line ? #string matching subject is line
         write( tab(find("frog")) )
end

#here's generating the first 1000 squares

procedure main()
    every write( squares() ) \1000 #truncate generator to 1000 results
end

procedure squares()
     n := 0
     repeat {
         n +:= 1
         suspend n^2 #shoot out next element of generator sequence
     }
end

procedure main()
    (n := 1) | |( n +:= 1, n^2 )
end

#So that
procedure main()
    every write(  (n := 1) | |( n +:= 1, n^2 )  ) \1000
end