home *** CD-ROM | disk | FTP | other *** search
/ Power CD-ROM!! 7 / POWERCD7.ISO / prgmming / clipper / acomp.prg next >
Text File  |  1993-10-14  |  2KB  |  69 lines

  1. /*
  2.  * GT CLIPPER STANDARD HEADER
  3.  *
  4.  * File......: acomp.prg
  5.  * Author....: Andy M Leighton
  6.  * BBS.......: The Dark Knight Returns
  7.  * Net/Node..: 050/069
  8.  * User Name.: Andy Leighton
  9.  * Date......: $Date$
  10.  * Revision..: $Revision$
  11.  *
  12.  * This is an original work by Andy Leighton and is placed in the
  13.  * public domain.
  14.  *
  15.  * Modification history:
  16.  * ---------------------
  17.  *
  18.  * $Log$
  19.  *
  20.  */
  21.  
  22. /*  $DOC$
  23.  *  $FUNCNAME$
  24.  *       GT_ACOMP()
  25.  *  $CATEGORY$
  26.  *       Array
  27.  *  $ONELINER$
  28.  *       Same as Nantucket/CA supplied AComp() but without the bugs
  29.  *  $SYNTAX$
  30.  *       GT_aComp(<aArray>, <bComp>, <nStart>, <nStop>) --> nPos
  31.  *  $ARGUMENTS$
  32.  *       <aArray>   - the array to compare
  33.  *       <bComp>    - the comparison block
  34.  *       <nStart>   - the element at which to start
  35.  *       <nStop>    - the element at which to stop
  36.  *  $RETURNS$
  37.  *       nPos       - the position of the element in the array which
  38.  *                    satisfies <bComp>
  39.  *  $DESCRIPTION$
  40.  *       Same as Nantucket/CA supplied AComp() but without the bugs
  41.  *  $EXAMPLES$
  42.  *  $END$
  43.  */
  44.  
  45. function GT_AComp(aArray, bComp, nStart, nStop)
  46.  
  47.    local value
  48.  
  49. /*
  50.  * NOTE: in the Nantucket supplied code value was always
  51.  *       initialised to aArray[1].  This is obviously wrong
  52.  *       where nStart > 1
  53.  */
  54.  
  55.    if nStart == NIL
  56.       value := aArray[1]
  57.    else
  58.       value := aArray[nStart]
  59.    endif
  60.  
  61.    aeval(                                                               ;
  62.           aArray,                                                       ;
  63.           {|x| value := if(eval(bComp, x, value), x, value)},           ;
  64.           nStart,                                                       ;
  65.           nStop                                                         ;
  66.         )
  67.  
  68. return value
  69.