mirror of
https://github.com/EiffelSoftware/eiffel-org.git
synced 2026-04-04 17:19:23 +02:00
Author:halw
Date:2010-02-03T20:59:49.000000Z git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@436 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
@@ -87,15 +87,15 @@ So, this usage of the loop construct has been the traditional mechanism for trav
|
||||
across my_list as c loop print (c.item) end
|
||||
</code>
|
||||
|
||||
Here the <code>across</code> indicates an iteration process across the structure <code>my_list</code>. The <code>as c</code> indicates that a cursor object referenced by the name <code>c</code>, and available only for the scope of the iteration, will be created to effect the iteration. The element of <code>my_list</code> which is currently referenced by the cursor <code>c</code> is <code>c.item</code> as you see in the call to <code>print (c.item)</code> loop body. The loop body does not contain the call to the structure's <code>forth</code> feature, as our more traditional example did. Neither do you see the call to <code>start</code> nor the check of <code>off</code> in the exit condition. The semantics of the iteration abstract these for you and relieve you of their burden ... and some opportunities for error.
|
||||
Here the <code>across</code> indicates an iteration process across the structure <code>my_list</code>. The <code>as c</code> indicates that a cursor object referenced by the name <code>c</code>, and available only for the scope of the iteration, will be created to effect the iteration. The element of <code>my_list</code> which is currently referenced by the cursor <code>c</code> is <code>c.item</code> as you see in the call to <code>print (c.item)</code> in the loop body. The loop body does not contain the call to the structure's <code>forth</code> feature, as our more traditional example did. Neither do you see the call to <code>start</code> nor the check of <code>off</code> in the exit condition. The semantics of the iteration abstract these for you, relieving you of their burden ... while eliminating some opportunities for error.
|
||||
|
||||
Concerning cursors, both ways of using the loop construct to traverse a structure employ a cursor. In the traditional usage, the cursor is internal to the structure object, the instance of <code>LINKED_LIST [STRING]</code> called <code>my_list</code>, in the case of the example. Applying the feature <code>item</code> to <code>my_list</code> retrieves the list element currently referenced by the cursor. In the iteration version of traversal, the variable <code>c</code> holds the iteration cursor, external to the list object. So, you apply <code>c.item</code> to get the current list element. The obvious use is for instructions that should be part of the system but executed only in some circumstances, for example to provide extra debugging information. The advantage to the external cursor is that multiple traversals of the structure can occur simultaneously without interfering with one another. This is possible in the traditional usage, but only by saving and restoring the structure's cursor.
|
||||
Concerning cursors, both ways of using the loop construct to traverse a structure employ a cursor. In the traditional usage, the cursor is internal to the structure object. In the case of the example, that would be the instance of <code>LINKED_LIST [STRING]</code> called <code>my_list</code>. Applying the feature <code>item</code> to <code>my_list</code> retrieves the list element currently referenced by the cursor. In the iteration version of traversal, the variable <code>c</code> holds the iteration cursor, external to the list object. So, you apply <code>c.item</code> to get the current list element. The advantage to the external cursor is that multiple traversals of the structure can occur simultaneously without interfering with one another. This is possible in the traditional usage, but only by saving and restoring the structure's cursor.
|
||||
|
||||
At first observation, it may not appear that both traversal examples are using the same language construct. But, indeed they are. In order to see this more clearly, it will help now to examine (almost) the entire anatomy of the loop construct.
|
||||
At first observation, it may not appear that both traversal examples are using the same language construct. But, indeed they are simply two different forms of a single language construct. In order to see this more clearly, it will help now to examine (almost) the entire anatomy of the loop construct.
|
||||
|
||||
===Debug===
|
||||
|
||||
An occasionally useful instruction is <code>debug</code> <code>(</code>''Debug_key'', ... <code>)</code> ''instructions'' <code>end</code> where ''instructions'' is a sequence of zero or more instructions and the part in parentheses is optional, containing if present one or more strings, called debug keys. The EiffelStudio compiler lets you specify the corresponding <code>debug</code> compilation option: <code>yes</code>, <code>no</code>, or an explicit debug key. The ''instructions'' will be executed if and only if the corresponding option is on.
|
||||
An occasionally useful instruction is <code>debug</code> <code>(</code>''Debug_key'', ... <code>)</code> ''instructions'' <code>end</code> where ''instructions'' is a sequence of zero or more instructions and the part in parentheses is optional, containing if present one or more strings, called debug keys. The EiffelStudio compiler lets you specify the corresponding <code>debug</code> compilation option: <code>yes</code>, <code>no</code>, or an explicit debug key. The ''instructions'' will be executed if and only if the corresponding option is on. The obvious use is for instructions that should be part of the system but executed only in some circumstances, for example to provide extra debugging information.
|
||||
|
||||
===Check===
|
||||
|
||||
|
||||
Reference in New Issue
Block a user