blob: 28fdeef36667e088b04eb59b3fddddbfbdceed91 (
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
|
@!---------------------------------------!
@! Start of FunnelWeb Example .fw File !
@!---------------------------------------!
@t vskip 40 mm
@t title titlefont centre "Powers:"
@t title titlefont centre "An Example of"
@t title titlefont centre "A Short"
@t title titlefont centre "FunnelWeb .fw File"
@t vskip 10 mm
@t title smalltitlefont centre "by Ross Williams"
@t title smalltitlefont centre "26 January 1992"
@t vskip 20 mm
@t table_of_contents
@A@<FunnelWeb Example Program@>
This program writes out each of the first @{p@} powers of the first @{n@}
integers. These constant parameters are located here so that they are easy to
change.
@$@<Constants@>==@{@-
n : constant natural := 10; -- How many numbers? (Ans: [1,n]).
p : constant natural := 5; -- How many powers? (Ans: [1,p]).@}
@B Here is the outline of the program. This FunnelWeb file generates a single
Ada output file called @{Power.ada@}. The main program consists of a loop that
iterates once for each number to be written out.
@O@<ex16.out@>==@{@-
@<Pull in packages@>
procedure example is
@<Constants@>
begin -- example
for i in 1..n loop
@<Write out the first p powers of i on a single line@>
end loop;
end example;
@}
@B In this section, we pull in the packages that this program needs to run. In
fact, all we need is the IO package so that we can write out the results. To use
the IO package, we first of all need to haul it in (@{with text_io@}) and then
we need to make all its identifiers visible at the top level (@{use text_io@}).
@$@<Pull in packages@>==@{with text_io; use text_io;@}
@B Here is the bit that writes out the first @{p@} powers of @{i@}. The power
values are calculated incrementally in @{ip@} to avoid the use of the
exponentiation operator.
@$@<Write out the first p powers of i on a single line@>==@{@-
declare
ip : natural := 1;
begin
for power in 1..p loop
ip:=ip*i;
put(natural'image(ip) & " ");
end loop;
new_line;
end;@}
@!---------------------------------------!
@! End of FunnelWeb Example .fw File !
@!---------------------------------------!
|