-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatoi_test.cl
46 lines (43 loc) · 1.05 KB
/
atoi_test.cl
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
(*
This method implements a driver for testing the ATOI class.
The program repeatedly asks the user to enter a number, which
is then coverted from its string form to an integer and back
again to a string. The results of both conversions are printed
on the screen. Typing "stop" at the prompt exits the program.
*)
class Main inherits IO {
newline() : Object {
out_string("\n")
};
prompt() : String {
{
out_string("Enter a number>");
in_string();
}
};
main() : Object {
(* Since we didn't bother to inherit from the A2I class, we have
to have an object of type A2I in order to access the
methods of that class. *)
(let z : A2I <- new A2I in
while true loop
(let s : String <- prompt() in
if s = "stop" then
abort() -- we don't bother to terminate gracefully
else
(let i : Int <- z.a2i(s) in
(let news : String <- z.i2a(i) in
{
out_int(i);
newline();
out_string(news);
newline();
}
)
)
fi
)
pool
)
};
};