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.

142 van Wijngaarden, et al.physics the results of which are collected by the computer), or to afilestore maintained by the operating system. A channel is a structuredvalue whose fields are routines returning truth values which determine theavailable methods of access to a book linked via that channel. Since themethods of access to a book may well depend on the book as well as onthe channel (e.g., a certain book may have been trapped so that it may beread, but not written to), most of these properties depend on both thechannel and the book. These properties may be examined by use of theenvironment enquiries provided for files (10.3.1.3.ff). Two environmentenquiries are provided for channels. These are:• estabpossible, which returns true if another file may be "established"(10.3.1.4.cc) on the channel;• standconv, which may be used to obtain the default "conversion key"(bb) for the channel.bb) A "conversion key" is a value of the mode specified by cony whichis used to convert characters to and from the values as stored in"internal" form and as stored in "external" form in a book. It is astructured value comprising a row of structures, each of which contains avalue in internal form and its corresponding external value. Theimplementation may provide additional conversion keys in its libraryprelude.cc) Three standard channels are provided, with properties as definedbelow (e,f,g). The implementation may provide additional channels in itslibrary-prelude. The channel number field is provided in order thatdifferent channels with otherwise identical possibilities may bedistinguished.}a)b)c)d)e)f)mode channel =slruct (proc (ref book) bool .~ reset, .~ set, .a get, .~ put, ~ bin,.~ compress, .~ reidf,proc bool .~ estab, proc pos .~ max pos,proc (rel book) conv .~ standconv, int .~ channel number) ;mode .~ cony = slruct ([1 : inl (skip)] strucl (char internal, external) F) ;proc estab possible = (channel chan) bool : estab of chan;proc standconv = (channel chan) proc (tel book) cony :standconv of chan;channel stand in channel = c a channel value whose field selected by'get' is a routine which always returns true, and whose otherfields are some suitable values c;channel stand out channel = c a channel value whose field selected by'put' is a routine which always returns true, and whose otherfields are some suitable values c ;g)10.3.1.3. FilesALGOL <strong>68</strong> Revised Report 143channel stand back channel = c a channel value whose fields selectedby 'set', 'reset', 'get', 'put' and 'bin' are routines which ahvaysreturn true, and whose other fields are some suitable values c ;{aa) A "file" is the means of communication between a particularprogramand a book which has been opened on that file via some channel.It is a structured value which includes a reference to the book to which ithas been linked (10.3.1.4.bb) and a separate reference to the text of thebook. The file also contains information necessary for the transputroutines to work with the book, including its current position cpos in thetext, its current "state" (bb), its current "format" (10.3.4) and the channelon which it has been opened.bb) The "state" of a file is determined by five fields:• read mood, which is true if the file is being used for input;• write mood, which is true if the file is being used for output;• char mood, which is true if the file is being used for charactertransput;• bin mood, which is true if the file is being used for binarytransput;• opened, which is true if the file has been linked to a book.cc) A file includes some "event routines", which are called whencertain conditions arise during transput. After opening a file, the eventroutines provided by default return false when called, but the programmermay provide other event routines. Since the fields of a file are not directlyaccessible to the user, the event routines may be changed by use of the"on routines" (1,m,n,o,p,q,r). The event routines are always given areference to the file as a parameter. If the elaboration of an event routineis terminated, then the transput routine which called it can take no furtheraction; otherwise, if it returns true, then it is assumed that the conditionhas been mended in some way, and, if possible, transput continues, but ifit returns false, then the system continues with its default action. The onroutines are:• on logicalfileend. The corresponding event routine is called when,during input from a book or as a result of calling set, the logical end ofthe book is reached (see 10.3.1.6.dd).Example:The programmer wishes to count the number of integers on hisinput tape. The file intape was opened in a surrounding range. If hewrites:begin int n : = O; on logical file end (intape, (ref file file) bool : gore f);do get (intape, Ioc int); n +:= 1 od;f: print (n)end,

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

Saved successfully!

Ooh no, something went wrong!