Function AEval() Foundation

Executes a code block for each array element.

Syntax
AEval( <aArray>, <bBlock>, ;
      [<nStart>], [<nCount>], [<lAssign>] ) --> aArray
Parameters
<aArray>
<aArray> is an array whose elements are passed to the code block.
<bBlock>
<bBlock> is a code block which is executed for each array element.
<nStart>
<nStart> is a numeric value specifying the first element in the array <aArray>, for which the code block is executed. The default value is 1.
<nCount>
<nCount> is a numeric value specifying the number of elements passed to the code block starting from position <nStart>. If <nCount> is missing, all elements from <nStart> to the last element of <aArray> are passed in sequence to the code block.
<lAssign>
The logical expression <lAssign> determines whether an assignment to the passed array element is permitted within the code block. If <lAssign> equals .T. (true), the array element is passed to the code block by reference. If an assignment to the first code block parameter is made, it is reflected in the corresponding array element.
Return

The return value of AEval() is a reference to <aArray>.

Description

The array function AEval() allows operations to be performed on the contents of array elements. The operations are programmed in a code block which is executed <nCount> times beginning with array element <nStart>. The contents of the current array element are passed to the code block as the first argument and the element index is passed as the second argument. After each execution, the index is incremented and the code block is evaluated with the next array element.

The contents of the array elements are not relevant to AEval(), since the function merely passes the contents of each element on to the code block. However, the code block must assure that only correct data types are processed.

Examples
Process arrays iteratively using AEval()

// In the example various uses of AEval() are shown. 

#include "Directry.ch" 

PROCEDURE Main 
   LOCAL aArray[5] 
                                 // fill array elements with 
                                 // consecutive numbers 
   AEval( aArray, {|x,i| aArray[i] := i } ) 
                                 // aArray is {1,2,3,4,5} 

                                 // Another way to do the same thing 
   AEval( aArray, {|x,i| x := i },,, .T. ) 
                                 // aArray is {1,2,3,4,5} 


   aArray := Directory("*.PRG")  // list file names 
   AEval( aArray, {|a| QOut( a[F_NAME] ) } ) 


   USE Customer NEW              // read data from a 
   aArray := Array( FCount() )   // DBF file into an array 
   AEval( aArray, {|x,i| aArray[i] := ; 
                        { PadR( FieldName(i), 10) , ; 
                          FieldGet(i) ; 
                        } ; 
                  } ) 

                                  // display data 
   AEval( aArray, {|a| QOut(a[1]+":", a[2]) } ) 

   CLOSE Customer 
RETURN 

Feedback

If you see anything in the documentation that is not correct, does not match your experience with the particular feature or requires further clarification, please use this form to report a documentation issue.