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,
144/van Wijngaarden, et al.ALGOL <strong>68</strong> Revised Report 145then the assignment to the field of intape violates the scoperestriction, since the scope of the routine (ref file file) boo/: goto f issmaller than the scope of intape, so he has to write:begin int n : = O; file auxin : = intape;on logical file end (auxin, (ref file file) bool : goto f);do get (auxin, Ioc int); n +: = 1 od;f: print (n)end.• on physical file end. The corresponding event routine is called whenthe current page number of the file exceeds the number of pages in thebook and further transput is attempted (see 10.3.1.6.dd).• onpageend. The corresponding event routine is called whenthe current line number exceeds the number of lines in the current pageand further transput is attempted (see 10.3.1.6.dd).• on line end. The corresponding event routine is called whenthe current character number of the file exceeds the number ofcharacters in the current line and further transput is attempted (see10.3.1.6.dd).Example:The programmer wishes automatically to give a heading at the startof each page on his file f:on page end (f, proc (ref file file) bool :(put (file, (newpage, "page number ", whole (i +: = 1, 0),newline)); frue)¢ it is assumed that i has been declared elsewhere ¢) .• on charerror. The corresponding event routine is called when acharacter conversion was unsuccessful or when, during input, acharacter is read which was not "expected" (10.3.4.1.11). The eventroutine is called with a reference to a character suggested as areplacement. The event routine provided by the programmer mayassign some character other than the suggested one. If the eventroutine returns true, then that suggested character as possibly modifiedis used.Example:The programmer wishes to read sums of money punched as"$123.45", ".$23.45", "..$3.45", etc.:on char error (stand in, (ref file f, ref char sugg) bool :if sugg = "0"then char c; backspace (f); get (f, c);(c = "$"1 get (f, sugg); gruel false)else falsefl );int cents; readf (($ 3z ","ridS, cents))• on value error. The corresponding event routine is called when:(i) during formatted transput an attempt is made to transput a valueunder the control of a "picture" with which it is incompatible, or whenthe number of "frames" is insufficient. If the routine returns true, thenthe current value and picture are skipped and transput continues; ifthe routine returns false, then first, on output, the value is output by •put, and next undefined is called;(ii) during input it is impossible to convert a string to a value of somegiven mode (this would occur if, for example, an attempt were made toread an integer larger than max int (10.2.1.c)).• on format end. The corresponding event routine is called when,during formatted transput, the format is exhausted while some valuestill remains to be transput. If the routine returns true, then undefinedis called if a new format has not been provided for the file by theroutine; otherwise, the current format is repeated.dd) The cony field of a file is its current conversion key (10.3.1.2.bb).After opening a file, a default conversion key is provided. Some otherconversion key may be provided by the programmer by means of a call ofmake conv (j). Note that such a key must have been provided in thelibrary-prelude.ee) The routine maketerm is used to associate a string with a file.This string is used when inputting a variable number of characters, any ofits characters serving as a terminator.ff) The available methods of access to a book which has been openedon a file may be discovered by calla of the following routines (note that theyield of such a call may be a function of both the book and the channel,and of other environmental factors not defined by this Report):• get possible, which returns true if the file may be used for input:• put possible, which returns true if the file may be used for output:• bin possible, which returns true if the file may be used for binarytransput:• compressible, which returns true if lines and pages will becompressed (lO.3.l.6.aa) during output, in which case the book is saidto be "compressible";• reset possible, which returns true if the file may be reset, i.e., itscurrent position set to (1, 1, 1);• set possible, which returns true if the file may be set, i.e., the currentposition changed to some specified value: the book is then said to be a"random access" book and, otherwise, a "sequential access" book:• reidfpossible, which returns true if the idf field of the book may bechanged;y• chan, which returns the channel on which the file has been opened(this may be used, for example, by a routine assigned byon physical file end, in.order to open another file on the same channel}.
- Page 2 and 3:
van Wijngaarden, et al.1.1.4.2. Par
- Page 4:
Acknowledgements{Habent sua fata li
- Page 8 and 9:
14 van Wijngaarden, et al.0.3.4. Mo
- Page 10 and 11:
. . . . . . . 4 " ' 0 . . . . . . .
- Page 12 and 13:
22 van Wijngaarden, et al.• let P
- Page 14 and 15:
26 van Wijngaarden, et al.{Since so
- Page 16 and 17:
30 van Wijngaarden, et aLloperandfo
- Page 18 and 19:
34 van Wijngaarden, et al.j) WHETHE
- Page 20 and 21:
38 van Wijngaarden, et al.A protono
- Page 22 and 23: 42 van Wijngaarden, et al.d) If N i
- Page 24 and 25: 46 van Wijngaarden, et al.c) {There
- Page 26 and 27: 50 van Wijngaarden, et al.c) The ph
- Page 28 and 29: 54 van Wijngaarden, et al.3.1.1. Sy
- Page 30 and 31: 58 van Wijngaarden, et al.where (RO
- Page 32 and 33: 62 van Wijngaarden, et al.1) SOlD N
- Page 34 and 35: 66 van Wijngaarden, et al.ALGOL 68
- Page 36 and 37: 70 van Wijngaarden, et el.For each
- Page 38 and 39: 74 van Wijngaarden, et al.If 'MODE"
- Page 40 and 41: 78 J van Wijngaarden, et al.C) SECO
- Page 42 and 43: 82 van Wijngaarden, et al.ALGOL 68
- Page 44 and 45: 86 van Wijngaarden. et al.ALGOL 68
- Page 46 and 47: 90 van Wijngaarden, et al.5.4.4.1.
- Page 48 and 49: 94van Wijngaarden, et al.ALGOL 68 R
- Page 50 and 51: 98 van Wijngaarden, et al.Assignati
- Page 52 and 53: 102 van Wijngaarden, et at.{A nest,
- Page 54 and 55: 106 van Wijngaarden, et al.'HEAD's
- Page 56 and 57: 110 van Wijngaarden, et al.ALGOL 68
- Page 58 and 59: 114van Wijngaarden, et al.ALGOL 68
- Page 60 and 61: 118 van Wijngaarden, et al.ALGOL 68
- Page 62 and 63: 122 van Wijngaarden, et al.style ii
- Page 64 and 65: 126 van Wijngaarden, et al.b) The c
- Page 66 and 67: 130van Wijngaarden, et al.ALGOL 68
- Page 68 and 69: 134van Wijngaarden, et al.ALGOL 68
- Page 70 and 71: 138d)e)f)g)h)i)J)k)1)m)n)van Wijnga
- Page 74 and 75: 146 van Wijngaarden, et al.gg) On s
- Page 76 and 77: 150van Wijngaarden, et al.ALGOL 68
- Page 78 and 79: 154/van Wijngaarden, et al.ALGOL 68
- Page 80 and 81: 158 van Wijngaarden, et el.fi;ref p
- Page 82 and 83: 162van Wijngaarden, et al.ALGOL 68
- Page 84 and 85: 166van Wijngaarden, et al.ALGOL 68
- Page 86 and 87: 170/van Wijngaarden, etal.ALGOL 68
- Page 88 and 89: 174J)K)L)M)N)O)P)a)b)c)d)e)van Wijn
- Page 90 and 91: 178/van Wijngaarden, et al.ALGOL 68
- Page 92 and 93: 182 van Wijngaarden, et al.• let
- Page 94 and 95: 186van Wijngaarden, et al./ALGOL 68
- Page 96 and 97: 190 van Wijngaarden, etal.composed
- Page 98 and 99: 194h)i)J)van Wijngaa(rden, et al.pr
- Page 100 and 101: 198 van Wijngaarden, et al.¢ strin
- Page 102 and 103: 202tvan Wijngaarden, et al.ALGOL 68
- Page 104 and 105: 206 van Wijngaa~den. et al.10.3.6.1
- Page 106 and 107: 210 van Wijngaarden, et al.!ALGOL 6
- Page 108 and 109: 214 van Wijngaarden, et al.inoperat
- Page 110 and 111: 218fvan Wijngaarden, et al.¢ move
- Page 112 and 113: 222 van Wijngaarden, etaL{overflow}
- Page 114 and 115: 226 van Wijngaarden, et al.ALGOL 68
- Page 116 and 117: 230max int 10.2.1.cmax real 10.2.l.
- Page 118 and 119: 234 van Wijngaarden, et al.ALGOL 68