-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-17.cl
60 lines (46 loc) · 1.55 KB
/
test-17.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
47
48
49
50
51
52
53
54
55
56
57
58
59
-- methodless-primes.cl
class Main inherits IO {
main() : Int { -- main() is an atrophied method so we can parse.
0
};
out : Int <- -- out is our 'output'. Its values are the primes.
{
out_string("2 is trivially prime.\n");
2;
};
testee : Int <- out; -- testee is a number to be tested for primeness.
divisor : Int; -- divisor is a number which may factor testee.
stop : Int <- 500; -- stop is an arbitrary value limiting testee.
m : Object <- -- m supplants the main method.
while true loop
{
testee <- testee + 1;
divisor <- 2;
while
if testee < divisor * divisor
then false -- can stop if divisor > sqrt(testee).
else if testee - divisor*(testee/divisor) = 0
then false -- can stop if divisor divides testee.
else true
fi fi
loop
divisor <- divisor + 1
pool;
if testee < divisor * divisor -- which reason did we stop for?
then -- testee has no factors less than sqrt(testee).
{
out <- testee; -- we could think of out itself as the output.
out_int(out);
out_string(" is prime.\n");
}
else -- the loop halted on testee/divisor = 0, testee isn't prime.
0 -- testee isn't prime, do nothing.
fi;
if stop <= testee then
"halt".abort() -- we could think of "halt" as SIGTERM.
else
"continue"
fi;
}
pool;
}; (* end of Main *)