-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathexcept.dylan
81 lines (57 loc) · 1.59 KB
/
except.dylan
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
module: except
synopsis: implementation of "Exception Handling" benchmark
author: Peter Hinely
copyright: public domain
define library except
use common-dylan;
use io;
end library;
define module except
use common-dylan, exclude: { format-to-string };
use format-out;
end module;
define variable hi :: <integer> = 0;
define variable lo :: <integer> = 0;
define sealed domain make (subclass(<hi-exception>));
define sealed domain initialize (<hi-exception>);
define class <hi-exception> (<error>)
constant slot number :: <integer>, required-init-keyword: number:; // not really used for anything
end;
define class <lo-exception> (<hi-exception>)
end;
define function some-function (num :: <integer>) => ()
block ()
hi-function(num);
exception (err :: <error>)
error("We shouldn't have got here.");
end;
end function;
define function hi-function (num :: <integer>) => ()
block ()
lo-function(num);
exception (err :: <hi-exception>)
hi := hi + 1;
end;
end function;
define function lo-function (num :: <integer>) => ()
block ()
blowup(num);
exception (err :: <lo-exception>)
lo := lo + 1;
end;
end function;
define function blowup (num :: <integer>) => ()
if (odd?(num))
signal(make(<lo-exception>, number: num));
else
signal(make(<hi-exception>, number: num));
end;
end function;
define function main () => ()
let arg = string-to-integer(element(application-arguments(), 0, default: "1"));
for (i from arg to 1 by -1)
some-function(i);
end;
format-out("Exceptions: HI=%d / LO=%d\n", hi, lo);
end function;
main();