Correction and clarification of open targets and open arguments.

Author:halw
Date:2010-08-16T12:42:22.000000Z


git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@657 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
halw
2010-08-16 12:42:22 +00:00
parent 3c1e5fd35e
commit 2fdba69432

View File

@@ -165,29 +165,33 @@ These possibilities give even more flexibility to the mechanism because they mea
you may write both you may write both
<code> <code>
your_account_list.do_all (agent deposit_one_grand) your_account_list.do_all (agent {ACCOUNT}.deposit_one_grand)
your_integer_list.do_all (agent add_to_n) your_integer_list.do_all (agent add_to_total)
</code> </code>
even though the two procedures used in the agents have quite different forms. We are assuming here that the first one, in class <code>ACCOUNT</code>, is something like even though the two procedures used in the agents have quite different forms. We are assuming here that the first one, a feature of class <code>ACCOUNT</code>, is something like
<code> <code>
deposit_one_grand deposit_one_grand
-- Add one thousand dollars to `balance' of account. -- Deposit one thousand into `Current'.
do do
balance := balance + 1000 deposit (1000)
end end
</code> </code>
so that it doesn't take an argument: it is normally called on its target, as in <code>your_account.deposit_one_grand</code>. In contrast, the other routine has an argument: The procedure <code>deposit_one_grand</code> takes no arguments. In the <code>do_all</code> example above, its target is open. The target will be, in turn, each instance of <code>ACCOUNT</code> in <code>your_account_list</code>.
In contrast, the other routine, assumed to be a feature of the calling class, does take an argument <code>x</code>:
<code> <code>
add_to_n (x: INTEGER) add_to_total (x: INTEGER)
-- Add `x' to the value of `total'. -- Add `x' to the value of `total'.
do do
total := total + x total := total + x
end end
</code> </code>
where <code>total</code> is an integer attribute of the enclosing class. Without the versatility of playing with open and closed arguments for both the original arguments and target, you would have to write separate iteration mechanisms for these two cases. Here you can use a single iteration routine of <code>LIST</code> and similar classes of EiffelBase, <code>do_all</code>, for both purposes: <br/> Here, <code>total</code> is assumed to be an integer attribute of the enclosing class. In the <code>do_all</code> example, each instance of <code>your_integer_list</code> will fill the argument <code>x</code> left open in <code>add_to_total</code>.
Without the versatility of playing with open and closed arguments for both the original arguments and target, you would have to write separate iteration mechanisms for these two cases. Here you can use a single iteration routine of <code>LIST</code> and similar classes of EiffelBase, <code>do_all</code>, for both purposes: <br/>
* Depositing money on every account in a list of accounts. * Depositing money on every account in a list of accounts.
* Adding all the integers in a list of integers. * Adding all the integers in a list of integers.