Showing posts from April, 2015

Ada 2012 Aspect Clauses => Static Predicates

John English wrote a wonderful book titled Ada95: The Craft of Object-Oriented Programming, which is available on line at In chapter 3 of that book he explores many Ada programming fundamentals using a simple calculator program example. The code for that example is:     with Ada.Text_IO, Ada.Integer_Text_IO;     use  Ada.Text_IO, Ada.Integer_Text_IO;     procedure Calculator is         Result   : Integer;         Operator : Character;         Operand  : Integer;     begin         Put ("Enter an expression: ");         Get (Result);                                   --  1         loop                                            --  2             loop                                        --  3                 Get (Operator);                 exit when Operator /= ' ';             end loop;             if Operator = '.' then                      --  4                 Put (Result, Width =&…

Parallel Addition Revisited

In an earlier article I discussed aspects of parallel addition of elements of an array. A more general problem would be to sum a set of numbers from a collection of numbers. The collection cannot be simply an arbitrary unending stream of numbers, because a sum of such a stream could never be completed. Instead, it must be some discrete sample size of numbers. Furthermore, the sample size cannot be zero. There must be at least one number in the sample or no sum is possible.
The following example collects a sample of numbers into a queue and then uses concurrent tasks to perform pair-wise addition of the queue elements. Each result of pair-wise addition is placed back on the queue. Eventually, given a discrete number of items in the queue, the queue will be left containing only one value. That value will be the total of all the operations on the set of numbers. This approach works because addition is commutative. The order the numbers are added is irrelevant to the solution. Parallel A…