Ada 2012 Tutorial
Parsing (and Streams)

Ada Lovelace, the namesake of the Ada programming language, considered the world’s first computer programmer
We left off the previous tutorial at parsing input from a user or a file, so we’re going to address that today. First, however, I need to introduce Streams.
Streams are a method to read or write any object to any medium, and thus they are doubly generalized. This also means that you are bounded by the most restrictive set of operations common to all mediums. As an example, you cannot provide position control in a general manner because not all transmission modes are random-access (like receiving a radio-signal), and not all streams are bi-directional (like a light-sensor).
In the informal parlance we’ve adopted we can just sat that all types have stream attributes, accessed with ‘Read and ‘Write, because all elementary types have them and the compiler knows how to compose compound types from elementary types, so you don’t normally have to keep track of elements in a compound type. (You do have to keep track of them if you’re writing both read and write that must be be functionally, rather than perfectly, inverse-operations; this is not a deficiency, but because you are implementing a protocol.)
So let’s see how to do it.
Continue reading





