From b65285c730e6140303da4c93096187a17307272e Mon Sep 17 00:00:00 2001 From: eiffel-org Date: Wed, 12 Sep 2018 16:38:48 +0000 Subject: [PATCH] Done some edition in the section 'General iteration facilities' - code section and paragraphs referencing features 'action' and 'test' that don't exist anymore. - feature 'exist' next to 'for_all' -> replaced by 'there_exists' - Changed last paragraph "All these features, and most ..." to correct for the fact that currently, the iteration routines accept arguments as pointed out in the comments by the user "Joe". Updated wikipage EiffelBase, Iteration. (Signed-off-by:WilliamsLima). git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2076 abb3cda0-5349-4a8f-a601-0c33ac3a8c38 --- .../eiffelbase-iteration.wiki | 42 ++----------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/documentation/18.07/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-data-structures-overview/eiffelbase-iteration.wiki b/documentation/18.07/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-data-structures-overview/eiffelbase-iteration.wiki index 7bab5c0d..baa45365 100644 --- a/documentation/18.07/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-data-structures-overview/eiffelbase-iteration.wiki +++ b/documentation/18.07/solutions/basic-computing/eiffelbase/eiffelbase-tutorial/eiffelbase-data-structures-overview/eiffelbase-iteration.wiki @@ -1,4 +1,4 @@ -[[Property:modification_date|Wed, 12 Sep 2018 14:20:54 GMT]] +[[Property:modification_date|Wed, 12 Sep 2018 16:38:48 GMT]] [[Property:publication_date|Wed, 12 Sep 2018 13:40:39 GMT]] [[Property:title|EiffelBase, Iteration]] [[Property:weight|6]] @@ -205,7 +205,7 @@ Of course the data structure class used in connection with a given iterator clas Class [[ref:libraries/base/reference/iterator_chart|ITERATOR]] defines the features that apply to all forms of iterator.
An iterator will always apply to a certain target structure. The target is introduced in [[ref:libraries/base/reference/iterator_chart|ITERATOR]] by the feature target: [[ref:libraries/base/reference/traversable_chart|TRAVERSABLE]] [G]
Both the iterator classes and the traversal classes are generic, with a formal generic parameter G. The actual generic parameters will be matched through the choice of iteration target: for a generic derivation of the form SOME_ITERATOR [ ACTUAL_TYPE] the target can only be of type SOME_TRAVERSABLE [ACTUAL_TYPE] for the same ACTUAL_TYPE, where SOME_TRAVERSABLE is the traversal class matching SOME_ITERATOR according to the preceding table ([[ref:libraries/base/reference/linear_chart|LINEAR]] for [[ref:libraries/base/reference/linear_iterator_chart|LINEAR_ITERATOR]] and so on), or one of its proper descendants.
-Each of the proper descendants of [[ref:libraries/base/reference/iterator_chart|ITERATOR]] redefines the type of target to the matching proper descendant of [[ref:libraries/base/reference/traversable_chart|TRAVERSABLE]] , to cover more specific variants of the iteration target, For example in [[ref:libraries/base/reference/linear_iterator_chart|LINEAR_ITERATOR]] the feature is redefined to be of type [[ref:libraries/base/reference/linear_chart|LINEAR]] . [[ref:libraries/base/reference/iterator_chart|ITERATOR]] also introduces the procedure for selecting a target: +Each of the proper descendants of [[ref:libraries/base/reference/iterator_chart|ITERATOR]] redefines the type of target to the matching proper descendant of [[ref:libraries/base/reference/traversable_chart|TRAVERSABLE]] , to cover more specific variants of the iteration target. For example in [[ref:libraries/base/reference/linear_iterator_chart|LINEAR_ITERATOR]] the feature is redefined to be of type [[ref:libraries/base/reference/linear_chart|LINEAR]]. [[ref:libraries/base/reference/iterator_chart|ITERATOR]] also introduces the procedure for selecting a target: set (s: like target) -- Make s the new target of iterations. @@ -218,44 +218,10 @@ Each of the proper descendants of [[ref:libraries/base/reference/iterator_chart| target /= Void end -Next [[ref:libraries/base/reference/iterator_chart|ITERATOR]] introduces the routines describing the elementary action and test that will be applied to items of the iteration targets: - - action - -- Action to be applied to item at current position in - -- target. - -- (default: item_action on item at current position.) - -- Note: for iterators to work properly, redefined - -- versions of this feature should not change the - -- traversable structure. - require - traversable_exists: target /= Void - not_off: not target.off - invariant_satisfied: invariant_value - do - item_action (target.item>) - ensure - not_off: not target.off - invariant_satisfied: invariant_value - end - - test: BOOLEAN - -- Test to be applied to item at current position in - -- target (default: value of item_test on item) - require - traversable_exists: target /= Void - not_off: not target.off - do - Result := item_test (target.item>) - ensure - not target.off - end - -These routines rely on two others, item_action and item_test, which both take an argument of type G, the formal generic parameter. The reason, already noted above, is that in a vast majority of cases the iterated action and test solely depend, at each step of the traversal, on the item (of type G) at the current position. To define an iteration process, then, it suffices to redefine item_action and item_test in a descendant of the appropriate iteration class. Only in complex cases will it be necessary to redefine action and test themselves.
-If you encounter such a case, note the caveat about action changing the target's structure. Understandably enough, an iterator that attempts to change the data structure while traversing it may engage in strange behavior. No such risk exists if you only redefine item_action, which may change the contents of items but not the structure itself.
Another feature introduced in [[ref:libraries/base/reference/iterator_chart|ITERATOR]] is the query invariant_value, describing invariant properties that must be ensured at the beginning of any iteration and preserved by every iteration step. As declared in [[ref:libraries/base/reference/iterator_chart|ITERATOR]] this query always returns true, but proper descendants can redefine it to describe more interesting invariant properties.
Finally, [[ref:libraries/base/reference/iterator_chart|ITERATOR]] introduces in deferred form the general iteration routines applicable to all iteration variants. They include two queries corresponding to the quantifiers of first-order predicate calculus: * for_all will return true if all items of the target structure satisfy test. -* exists will return true if at least one item satisfies test. +* there_exists will return true if at least one item satisfies test. The other routines are commands which will traverse the target structure and apply action to items selected through test: * do_all applies action to all items. @@ -264,7 +230,7 @@ The other routines are commands which will traverse the target structure and app * do_until, to all items up to and including the first one that satisfies test. * while_do and do_while, to all items up to the first one that does not satisfy test. (This can also be achieved with until_do or do_until by choosing the opposite test.) -All these features, and most of the other iteration features introduced in proper descendants of [[ref:libraries/base/reference/iterator_chart|ITERATOR]] and described next, have no argument. Information about the target of iteration comes from feature target, set by procedure set; information about what needs to be done for each item of the target structure comes from item_action and item_test. +Some of these features and most of the other iteration features introduced in proper descendants of [[ref:libraries/base/reference/iterator_chart|ITERATOR]] and described next, have either an action argument that must be of type PROCEDURE [G] or an argument test of type FUNCTION [G, BOOLEAN]. Some have both. Information about the target of the iterations comes from feature target, set by procedure set; information about what needs to be done for each item of the target structure comes from the argument action passed to the routines referenced above. ==Linear and chain iteration==