aboutsummaryrefslogtreecommitdiff
path: root/comparison/Inpla/src/bsort-40000-reuse.in
blob: 5908f83b1cfb2c3db15253984686827bf2620ef4 (plain) (blame)
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
// Bubble sort
bsort(ret) >< [] => ret~[];
bsort(ret) >< x:xs => (*L)bsort(ret)~cnt, (*R)B(cnt, x)~xs;
bsort(ret) >< M(x) => ret~x;

B(ret, int x) >< [] => ret~M([x]);
B(ret, int x) >< M(w) => ret~M(x:w);
B(ret, int x) >< (int y):ys
| x<y => ret~(*R)(x:cnt), (*L)B(cnt, y)~ys
| _   => ret~(*R)(y:cnt), (*L)B(cnt, x)~ys;


// Creates a random list
make_RandList(ret) >< (int n)
| n>0 => ret~(rd:cnt), (*L)make_RandList(cnt)~(n-1) 
  where rd=rand(10000)
| _ => ret~[];


// validation checks
valid(ret) >< [] => ret~False;
valid(ret) >< x:xs => (*L)valid_Cons(ret,x)~xs;

valid_Cons(ret, int x) >< [] => ret~True;
valid_Cons(ret, int x) >< (int y):ys
| x<=y => (*L)valid_Cons(ret,y)~ys
| _ => ret~False, Eraser~ys;

// The `Eraser' is a built-in agent defined for any agents as follows:
//Eraser >< Alpha(a1, ..., a5) => Eraser~a1, ..., Eraser~a5;


// Main
const LIST_ELEM=40000;

make_RandList(rndlist)~(LIST_ELEM),
bsort(sorted)~rndlist,
valid(ret)~sorted;

ret;