Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper 5.2 . The Guide To CA-Clippe - <b>aeval()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 AEVAL()
 Execute a code block for each element in an array
------------------------------------------------------------------------------
 Syntax

     AEVAL(<aArray>, <bBlock>,
        [<nStart>], [<nCount>]) --> aArray

 Arguments

     <aArray> is the array to traverse.

     <bBlock> is a code block to execute for each element encountered.

     <nStart> is the starting element.  If not specified, the default is
     element one.

     <nCount> is the number of elements to process from <nStart>.  If not
     specified, the default is all elements to the end of the array.

 Returns

     AEVAL() returns a reference to <aArray>.

 Description

     AEVAL() is an array function that evaluates a code block once for each
     element of an array, passing the element value and the element index as
     block parameters.  The return value of the block is ignored.  All
     elements in <aArray> are processed unless either the <nStart> or the
     <nCount> argument is specified.

     AEVAL() makes no assumptions about the contents of the array elements it
     is passing to the block.  It is assumed that the supplied block knows
     what type of data will be in each element.

     AEVAL() is similar to DBEVAL() which applies a block to each record of a
     database file.  Like DBEVAL(), AEVAL() can be used as a primitive for
     the construction of iteration commands for both simple and complex array
     structures.

     Refer to the Code Blocks section in the Basic Concepts chapter of the
     Programming and Utilities guide for more information on the theory and
     syntax of code blocks.

 Examples

     .  This example uses AEVAL() to display an array of filenames and
        file sizes returned from the DIRECTORY() function:

        #include "Directry.ch"
        //
        LOCAL aFiles := DIRECTORY("*.dbf"), nTotal := 0
        AEVAL(aFiles,;
           { | aDbfFile |;
              QOUT(PADR(aDbfFile[F_NAME], 10), aDbfFile[F_SIZE]),;
              nTotal += aDbfFile[F_SIZE]);
           } )
        //
        ?
        ? "Total Bytes:", nTotal

     .  This example uses AEVAL() to build a list consisting of
        selected items from a multidimensional array:

        #include "Directry.ch"
        //
        LOCAL aFiles := DIRECTORY("*.dbf"), aNames := {}
        AEVAL(aFiles,;
           { | file | AADD(aNames, file[F_NAME]) };
           )

     .  This example changes the contents of the array element
        depending on a condition.  Notice the use of the codeblock
        parameters: */

        LOCAL aArray[6]
        AFILL(aArray,"old")
        AEVAL(aArray,;
        {|cValue,nIndex| IF(cValue == "old",;
                         aArray[nIndex] := "new",)})

 Files:  Library is CLIPPER.LIB.

See Also: DBEVAL() EVAL() QOUT()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson