Results 1 -
1 of
1
Simulating file operations: an exercise in calculational data refinement. Memorandum AB66
- Eindhoven University of Technology
, 1997
"... This note was written as an exercise in calculating with abstract data type specifications, both from the user’s point of view and from the implementer’s. We have chosen an example that is well-known to anyone who has ever struggled to convert programs involving ISO Pascal file operations to some no ..."
Abstract
-
Cited by 1 (1 self)
- Add to MetaCart
This note was written as an exercise in calculating with abstract data type specifications, both from the user’s point of view and from the implementer’s. We have chosen an example that is well-known to anyone who has ever struggled to convert programs involving ISO Pascal file operations to some nonstandard Pascal version – an experience by now familiar to a sizable proportion of the earth’s population. In order to derive a solution to this problem, we regard ISO Pascal files as an abstract data type, disregarding the fact that Pascal compilers will not support this. We specify this abstract data type by giving a model, i.e. we define a number of variables of mathematically well-understood types in terms of which the operations on ISO Pascal files can be described. Let a component type T be given. Our model consists of four variables, namely P: T ∗ S: T ∗ (the file prefix, consisting of the items already read) (the file suffix, consisting of the items not yet read) Q: {in, out} (whether the file is opened for input or for output) B: T ∪ {⊥} (the file buffer) The values of these four variables are not quite independent: they are linked by the type invariant Q = out ⇒ S = [ ]. (1) In the ISO Pascal definition, the file buffer is a public variable: client variables may inspect its value, but are also allowed to perform explicit assignments to it. In our abstract data type, we shall model this by adding operations Getbuffer and Setbuffer whose effects are those of inspection and assignment respectively. The value ⊥ (pronounced ‘bottom’) is added because the ISO Pascal standard sometimes requires the buffer to become undefined. The abstract data type for ISO Pascal files is defined by listing its operations and specifying these by pre- and postconditions in terms of the four variables P, S, Q, B. The operations are: Rewrite pre: true post: P = [ ] ∧ S = [ ] ∧ Q = out ∧ B = ⊥ Reset pre: true post: P = [ ] ∧ S = P • ++ S • ∧ Q = in ∧ B = Hd.S Put pre: Q = out ∧ B � = ⊥ post: P = P • ++ [B•] ∧ S = [ ] ∧ Q = out ∧ B = ⊥ Get pre: Q = in ∧ S � = [] post: P = P • ++ [Hd.S•] ∧ S = Tl.S • ∧ Q = in ∧ B = Hd.S Setbuffer(E) pre: def.E

