home *** CD-ROM | disk | FTP | other *** search
- // test if two binary trees have the same leaves
- // the trees can be represented by sequences of sequences
- // task pi (i=1,2) outputs the next leaf of tree i
- // task p3 inputs two values and tests for equality
-
- next(x,out) {if(x==[]) return;
- if(is_number x) {out!x;return;}
- next(hd x,out);
- next(tl x,out);};
- eos="eos";
- ch1=channel();
- ch2=channel();
- tree1=[1,[2,[3],4]];
- tree2=[[1,2],3,[4]];
- task p1(out) {print "starting p1";next(tree1,out);
- out!eos;};
- task p2(out) {print "starting p2";next(tree2,out);
- out!eos;};
- task p3(in1,in2;x,y) {print "starting p3";in1?x;in2?y;
- while((x!=eos) || (y!=eos))
- {if(x!=y) {writeln("not equal");skip;}
- in1?x;in2?y;
- }
- writeln("equal");};
- task main() {start p1(ch1);
- start p2(ch2);
- start p3(ch1,ch2);};
- end
-