158 van Wijngaarden, et el.fi;ref pos cpos = ClJOS off, lpos = lpos of book off;pos ccpos = cpos;if (cpos : = (p, l, c)) beyond lposthen cpos : = lpos;(- (logical file mended off) (f) I undefined);set mood (f, reading)elif pos bounds = book bounds (f);p < 1 v p > p of bounds + 1v l< 1 v l> lofbounds + 1v c < 1 v c> cofbounds+lthen cpos := ccpos; undefinedfij) proc reset = (ref file f) void :if - opened off v , reset possible (f) then undefinedelseref bool (read mood off) : = - put possible (f);ref bool (write mood off) : = - get possible (f);ref bool (char mood off) : = - bin possible (f);ref bool (bin mood off) : = false;ref pos (cpos off) := (I, 1, 1)fl;k) proc set char number = (ref file f, int c) void :if - opened off then undefinedelse ref ref pos cpos = cpos of f;while c of cpos ~ cdoif c < 1 v c > c of book bounds (f) + 1then undefinedelif c > c of cposthen space (f)else backspace (f)fiodfi;10.3.2. Transput values10.3.2.1. Conversion routines{The routines whole, fixed and float are intended to be used with theformatless output routines put, print and write when it is required to havea little extra control over the layout produced. Each of these routines hasa width parameter whose absolute value specifies the length of the stringto be produced by conversion of the arithmetic value Y provided. Each offixed and float has an after narameter to specify the number of digitsrequired after the decimal point, and an exp parameter in float specifiesthe width allowed for the exponent. If V cannot be expressed as a stringALGOL <strong>68</strong> Revised Report 159within the given width, even when the value of after, if provided, has beenreduced, then a string filled with errorchar (10.2.l.t) is returned instead.Leading zeroes are replaced by spaces and a sign is normally included.The user can, however, specify that a sign is to be included only fornegative values by specifying a negative width. If the width specified iszero, then the shortest possible string into which Y can be converted,consistently with the other parameters, is returned. The followingexamples illustrate some of the possibilities:print (whole (i, -4))which might print "...0", "..99", ".-99", "9999" or, if i weregreater than 9999, '....... , where ..... is the yield of errorchar:print (whole (i, 4))which would print ".+99" rather than "..99":print (whole (i, 0))which might print "0", "99", "-99", "9999" or "99999":print (fixed (x, -6, 3))which might print ".2.718", "27.183" or "271.83" (in which oneplace after the decimal point has been sacrificed in order to fitthe number in);print (fixed (x, O, 3))which might print "2.718", "27.183" or "271.828";print (float (x, 9, 3, 2))which might print "-2.7181o+0", "+2.7181o-1", or "+2.72~o+11" (inwhich one place after the decimal point has been sacrificed inorder to make room for the unexpectedly large exponent).}a) mode g number = union (~ L real~, ~ L int~) ;b) proc whole = (number v, int width) string :case v in{ (L int x):(int length : = abs width - (x < L 0 v width > 0 } ] I 0),Lint n : = abs x;if width = 0 thenLint m : = n; length : = O;whilem +:= L lO; length+:= I; m~ LOdo skip odfi;string s : = subwhole (n; length);if length = 0 v char in string (errorchar, Ioc int, s)then abs width x errorcharelse(x < L 01 ..... I: width > 01 "+"1 "") plusto s;(width ~ O I (abs width - upb s) x ,£,~lplusto s);Sfi)~,~ (L real x): fixed(x, width, 0) 7esac ;
160van Wijngaarden, et al./ALGOL <strong>68</strong> Revised Report161c)d)proc fixed = (number v, int width, after) string :case v in(L real x):if int length : = abs width - (x < L 0 v width > 01 11 0);after >_ 0 ^ (length > after v width = O)then L real y = abs x;if width = 0then length : = (after = 0 [ i I 0);while y + L.5 x L.l I after >_L lO I lengthdo length +:= 1 od;length +: = (after = 0 [ 0 [ after + 1)fl;string s := subfixed (y, length, after);if - char in string (errorchar, Ioc int, s)then (length > upb s a y < IL 1.0[ "O" plusto s);(x < L 01 ..... l: width > 01 "+"[ "") plusto s;(width ~ O I (abs width - upb s) x '£':lplusto s);8elif after > 0then fixed (v, width, after - 1)else abs width x errorcharflelse undefined; abs width x errorchartit",It (Lint x): fixed (L real (x), width, after) ~"esac ;proc float = (number v, int width, after, exp) string :case v in(L real x):if int before = abs width - abs exp - (after ~ 01 after + 1 I O) - 2;sign before + sign after > 0then string s, L real y : = abs x, int p : = O;L standardize (y, before, after, p);s:=fixed (sign x x y, sign width x (abs width - abs exp - 1),after) + "1o" + whole (p, exp);if exp = 0 V char in string (errorchar, Ioc int, s)thenfloat (x, width, (after ~ 01 after - 1 [ 0),(exp > 0 [ exp + 1 [ exp - 1))else sfielse undefined; abs width x errorchartit,(Lint x): float (L real (x), width, after, exp) #esac ;e)f)g)h)proc 9 subwhole = (number v, int width) string :¢ returns a string of maximum length 'width' containing adecimal representation of the positive integer 'v' ¢case v In~ (L int x):esac ;begin string s, L int n : = x;while dig char (8 (n mod JL 10)) plusto s;n s:= L lO; n~ LOdo skip od;(upb s > width I width x errorchar l s)endproc .~ subfixed = (number v, int width, after) string :¢ returns a string of maximum length 'width' containing arounded decimal representation of the positive real number'v'; if 'after' is greater than zero, this string contains adecimal point followed by 'after' digits ¢case v in(L real x):begin siring s, int before : = O;L real y : = x + L .5 x L .1 I after;proc choosedig = (ref L real y) char :dig char (tint c : = S entier (y x: = L 10.0); (c > 91 c : = 9);y -: = Kc; c));while y _> IL 10.0 I before do before +: = 1 od;y/: = L 10.0 I before;to before do s plusab choosedig (y) od;(after > 0 [ s plusab ".");to after do s plusab choosedig (y) od;(upb s > width [ width x errorchar J s)endesac ;proc 9 L standardize = (ref L real y, int before, after, ref int p) void :¢ adjusts the value of 'y' so that it may be transput accordingto the format $ n(before)d . n(after)d $; 'p' is set so t/zaty x 10 t p is equal to the original value of 'y'¢beginJL realg = L 10.0 I before; L real h = g × L .1;whiley >_g doyx:= L .1; p+:= 1 od;(y~ JLO.O I while y < h do yx:= L 10.0; p -:= 1 od);(y+L.5xL.1 l after>_gly:=h; p+:= l)end;proc 9 dig char = tint x) char : "0123456789abcdef" I x + i I :
- 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 72 and 73: 142 van Wijngaarden, et al.physics
- 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 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