10.07.2015 Views

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

Algol 68 - ACM Digital Library

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

216/van Wijngaarden, et al.ALGOL <strong>68</strong> Revised Report217flend,(title ~ title of bookI next of book : = heap book : = (title, nil))¢ list ¢begin getf (input, name); update;putf (output, ($p" author: "30all$, name));if rb (book := book of auth) :=: nilthen put (output, ("no publications", newline))else on page end (output,(ref file f) bool :(putf (f, ($p" author: "30a41k" continued"ll$, name));true));while rb (book) : ~: nildo putf (output, ($180a$, title of book)); book:= next of bookod;on page end (output, (fertile f) bool : false)flend,¢ find ¢begin getf (input, (Ioc string, title)); auth : = first auth;whlle ra (auth) :~: nildo book := book of auth;while rb (book) : ~: nildoif title = title of bookthen putf (output, ($l"author: "30a$, name of auth));go to try againelse book : = next of bookfiod;auth : = next of authod;put (output, (newline, "unknown", newline))end,11.12. Cooperating sequential processesbegin int nmb magazine slots, nmb producers, nmb consumers;read ((nmb magazine slots, nmb producers, nmb consumers));[1 : nmb producers ] file infile, [1 : nmb consumers ] file outfile;for i to nmb producers do open (infile [ i ], "", inchannel [ i ]) od;¢ 'inchannel' and 'outchannel' are defined in a surroundingrange ¢for i to nmb consumersdo open (outfile [ i ], "", outchannel [ i ]) od;modepage= [1 : 60, 1 : 132] char;[1 : nmb magazine slots] ref page magazine;int ¢ pointers of a cyclic magazine ¢ index : = 1, exdex : = 1;sema full slots = level O, free slots = level nmb magazine slots,in buffer busy = level 1, out buffer busy = level 1;proc par call = (proc (int) void p, int n) void :¢ call 'n' incarnations of 'p' in parallel ¢(n > 01 par (p (n), par call (p, n - 1)));proc producer = tint i) void :do heap page page;get (infile [ i ], page);down free slots; down in buffer busy;magazine [index] : = page;index modab nmb magazine slots plusab 1;up full slots; up in buffer busyod;proc consumer = tint i) void :do page page;down full slots; down out buffer busy;page := magazine [ exdex ];exdex modab nmb magazine slots plusab 1;up free slots; up out buffer busy;put (outfile [ i ], page)od;par (par call (producer, nmb producers),par call (consumer, nmb consumers))endodendesec¢ end ¢(put (output, (new page, "signed off", close)); close (input);goto stop),¢ error ¢(put (output, (newline, "mistake, try again")); newline (input))11.13. Towers of Hanoifork to8do file f: = stand out;proc p = tint me, de, ma) void :if ma > 0 thenp (me, 6 - me - de, ma - 1);putf (f, (me, de, ma));

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!