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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
|
############################################################################
#
# File: seqimage.icn
#
# Subject: Procedures to produce string image of Icon result sequence
#
# Author: Ralph E. Griswold
#
# Date: June 20, 1997
#
############################################################################
#
# This file is in the public domain.
#
############################################################################
#
# The procedure Seqimage{e,i,j} produces a string image of the
# result sequence for the expression e. The first i results are
# printed. If i is omitted, there is no limit. If there are more
# than i results for e, ellipses are provided in the image after
# the first i. If j is specified, at most j results from the end
# of the sequence are printed after the ellipses. If j is omitted,
# only the first i results are produced.
#
# For example, the expressions
#
# Seqimage{1 to 12}
# Seqimage{1 to 12,10}
# Seqimage{1 to 12,6,3}
#
# produce, respectively,
#
# {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12}
# {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, ...}
# {1, 2, 3, 4, 5, 6, ..., 10, 11, 12}
#
#
# Warning: If j is not omitted and e has an infinite result sequence,
# Seqimage{} does not terminate.
#
############################################################################
procedure Seqimage(L)
local seq, result, i, j, resid
seq := ""
i := @L[2]
j := @L[3]
while result := image(@L[1]) do
if *L[1] > \i then {
if /j then {
seq ||:= ", ..."
break
}
else {
resid := [", " || result]
every put(resid,", " || image(|@L[1]))
if *resid > j then seq ||:= ", ..."
every seq ||:= resid[*resid -j + 1 to *resid]
}
}
else seq ||:= ", " || result
return "{" || seq[3:0] || "}" | "{}"
end
|