ack/lang/occam/test/sort.ocm

50 lines
809 B
Plaintext
Raw Normal View History

1987-02-25 17:14:10 +00:00
#include "dec.ocm"
-- This file contains a recursive call to sorter, so this is not really Occam.
1987-02-25 17:14:10 +00:00
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