On 05/04/2008 15:03, in article
L-udnRBPxNSpGWranZ2dnUVZ_gKdnZ2d@[EMAIL PROTECTED]
"pakman"
<pakman744@[EMAIL PROTECTED]
> wrote:
> Recently, in the process of illustrating Ada 95 child packages in a
course I
> teach, I implemented the Fractions.Comparisons package from N. Cohen's
Ada
> as a Second Language, 2nd ed text. In the test program, I withed the
> Fractions and Fractions.Comparisons packages, and then specified the use
> type Fractions.Fraction_Type for direct visibility of the Fractions
package
> operators. I was surprised that the Fractions.Comparisons package
operators
> were not directly visible (that is, I was not able to test for A < B).
To
> make the example work, I added the use Fractions.Comparisons statement.
>
> So, my questions are: 1) Why didn't the use type work for the
> Fractions.Comparisons operators, and 2) how do I make the operators
directly
> visible?
(1) Because the operations in Fractions.Comparisons are not primitive
operations of the fraction type.
(2) Redesign the package structure (abolish Fractions.Comparisons) so that
the comparisons are primitive.
Cohen is illustrating child packages here. The example should not be taken
as a paradigm of good ADT methodology in Ada, because it is far from that.
(Moreover, the comparison algorithm is excessively prone to overflow.)
>
> While this is an academic exercise, actual projects using this
combination
> of parent and child packages have experienced similar problems.
Refactoring needed!
--
Bill Findlay
<surname><forename> chez blueyonder.co.uk


|