Annotation of 43BSD/contrib/icon/samples/pdco.icn, revision 1.1.1.1

1.1       root        1: #
                      2: #          D E F I N E D   C O N T R O L   O P E R A T I O N S
                      3: #
                      4: 
                      5: #  This program illustrates how programmer-control operations can be
                      6: #  implemented in Icon using co-expressions and the p{ ... }
                      7: #  syntax that facilitates their use.
                      8: 
                      9: procedure main()
                     10:    every write(Galt{1 to 10,!"abcd",1 to 10})
                     11:    write(Seqimage{star("abc") \ 10})
                     12:    write(Seqimage{1 to 1000,5})
                     13:    write("---")
                     14:    every write(Limit{1 to 100,3})
                     15:    write("---")
                     16:    every write(Ranseq{!"abcd",1 to 10})
                     17: end
                     18: 
                     19: procedure star(s)
                     20:    suspend "" | (star(s) || !s)
                     21: end
                     22: 
                     23: procedure Galt(a)
                     24:    local e
                     25:    every e := !a do suspend |@e
                     26: end
                     27: 
                     28: procedure Limit(a)
                     29:    local i, x
                     30:    while i := @a[2] do {
                     31:       a[1] := ^a[1]
                     32:       every 1 to i do
                     33:          if x := @a[1] then suspend x
                     34:          else break
                     35:       }
                     36: end
                     37: 
                     38: procedure Ranseq(a)
                     39:    local x
                     40:    while x := @?a do suspend x
                     41: end
                     42: 
                     43: procedure Seqimage(a)
                     44:    local seq, result, i
                     45:    seq := ""
                     46:    i := @a[2]
                     47:    while result := image(@a[1]) do
                     48:       if *a[1] > \i then {
                     49:          seq ||:= ", ..."
                     50:          break
                     51:          }
                     52:       else seq ||:= ", " || result
                     53:    return "{" || seq[3:0] || "}" | "{}"
                     54: end

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.