50 lines
809 B
Plaintext
50 lines
809 B
Plaintext
#include "dec.ocm"
|
|
-- This file contains a recursive call to sorter, so this is not really Occam.
|
|
|
|
var c:
|
|
seq
|
|
c:='*s'
|
|
proc comparator(value num, chan in, out)=
|
|
var old.num, new.num:
|
|
seq
|
|
old.num:=num
|
|
in ? new.num
|
|
while new.num
|
|
seq
|
|
in ? new.num
|
|
if
|
|
new.num<=old.num
|
|
out ! true; new.num
|
|
new.num>old.num
|
|
seq
|
|
out ! true; old.num
|
|
old.num:=new.num
|
|
in ? new.num
|
|
out ! true; old.num; false
|
|
:
|
|
proc sorter(chan out)=
|
|
chan in:
|
|
var num:
|
|
seq
|
|
decin(input, num, c)
|
|
if
|
|
c<0
|
|
out ! false
|
|
c>=0
|
|
par
|
|
sorter(in)
|
|
comparator(num, in, out)
|
|
:
|
|
chan out:
|
|
var num:
|
|
par
|
|
sorter(out)
|
|
seq
|
|
out ? num
|
|
while num
|
|
seq
|
|
out ? num
|
|
decout(output, num, 0)
|
|
output ! '*n'
|
|
out ? num
|