In Section 9.3.1 we noted that Ada 83 does not permit subroutines to be passed as parameters,

Question:

In Section 9.3.1 we noted that Ada 83 does not permit subroutines to be passed as parameters, but that some of the same effect can be achieved with generics. Suppose we want to apply a function to everymember of an array.
We might write the following in Ada 83:

generic type item is private; type item_array is array (integer range ) of item; with function F(it : in item) return item; procedure apply_to_array (A in out item array); procedure apply_to_array (A : in out item_array) is begin for i in A'first..A'last loop A(i) := F(A(i)); end loop; end apply_to_array;

Given an array of integers, scores, and a function on integers, foo, we can write:

How general is this mechanism? What are its limitations? Is it a reasonable substitute for formal (i.e., second-class, as opposed to third class) subroutines?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: