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
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:

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?
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;
Step by Step Solution
3.38 Rating (173 Votes )
There are 3 Steps involved in it
The limitation of this programming idiom is that the generic subroutine ap... View full answer
Get step-by-step solutions from verified subject matter experts
