Author Archives: EFish

Ada 2012 Tutorial #2

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

facebooktwittergoogle_plusredditpinterestlinkedinmail

Ada 2012 Tutorial #1

Ada 2012 Tutorial

Ada Lovelace, the namesake of the Ada programming language, considered the world’s first computer programmer

    Welcome to the tutorial! I will be making some assumptions which are fairly safe: first, that you are unfamiliar with the Ada language; second, you have at least some interest in discovering what it is about; third, that you have some programming experience; and last, that you have an Ada Compiler. (There’s a free one available from AdaCore here, and the GCC has one as well.)
    Ada is probably different than what programming languages you are likely to be familiar with, this is a result of Ada’s design goals — two of which are safety and maintainability. The first means that Ada tries to do a lot of checking up-front, in compilation if possible, which reduces the time spent debugging at the cost of the compiler rejecting erroneous source. That can be frustrating at times, but it is better than having to spend three days tracking down a bug. This leads us to the second difference, Ada was designed to be highly maintainable, even across large teams, which is evident in its package system.
    To introduce the language I will use a small and simple (read as ‘toy’) LISP-like interpreter. To begin with, we need to realize that LISP runs on a loop of read-input, evaluate, and print.

Continue reading

facebooktwittergoogle_plusredditpinterestlinkedinmail