Page 1 of 1
					
				aEVAL
				Posted: Tue Oct 11, 2016 4:14 pm
				by unixkd
				Hi All
Is it possible to extend aEval(...) like: Call it DC_AEval(...)
DC_AEval( <aArray>, <bBlock>, [<nStart>], [<nCount>], [<lAssign>],[<bFor>], [<bWhile>] ) --> aArray
Similar to DC_ForNext(...)
DC_ForNext ( <nStart>, ;
              <nEnd>, ;
             [<nStep>], ;
              <bEval>, ;
             [<bWhile>],;
             [<bFor>] ) -> NIL
Thanks.
Joe.
			 
			
					
				Re: aEVAL
				Posted: Tue Oct 11, 2016 4:42 pm
				by rdonnay
				What is <lAssign> for?
			 
			
					
				Re: aEVAL
				Posted: Tue Oct 11, 2016 5:02 pm
				by rdonnay
				Here is the function you wanted, with the exception of lAssign.
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "directry.CH"
FUNCTION Main()
LOCAL aDir, bEval, bFor, bWhile
aDir := Directory('C:\exp20\source\dclipx\*.*')
wtf aDir
bEval := {|a|Qout(Pad(a[F_NAME],20)),QQout(a[2])}
bFor := {|a|a[F_SIZE] > 2000 }
bWhile := {|a|a[F_SIZE] < 200000 }
DC_AEval( aDir, bEval,,,, bFor, bWhile)
wtf 'stop' pause
RETURN nil
* ------------
FUNCTION DC_Aeval( aArray, bBlock, nStart, nCount, lAssign, bFor, bWhile )
LOCAL nLen := Len(aArray), i, n := 0
DEFAULT nStart := 1, ;
        nCount := nLen
FOR i := nStart TO nLen
  IF n++ >= nCount
    EXIT
  ENDIF
  IF !Empty(bWhile) .AND. !Eval(bWhile,aArray[i])
    EXIT
  ENDIF
  IF Empty(bFor) .OR. Eval(bFor,aArray[i])
    Eval( bBlock, aArray[i] )
  ENDIF
NEXT
RETURN aArray
 
			
					
				Re: aEVAL
				Posted: Wed Oct 12, 2016 12:45 am
				by unixkd
				Thanks Roger
lAssign is as used in aEval() function of Xbase++
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.
Joe
			 
			
					
				Re: aEVAL
				Posted: Wed Oct 12, 2016 6:17 am
				by rdonnay
				lAssign is as used in aEval() function of Xbase++
I never noticed that parameter before.
Here is an updated DC_Aeval() function and a new test program.
DC_AEval() is first called to change the file names in the array to upper case.
DC_AEval() is then called to output the file names and sizes to the screen.
Code: Select all
#INCLUDE "dcdialog.CH"
#INCLUDE "directry.CH"
FUNCTION Main()
LOCAL aDir, bEval, bFor, bWhile
aDir := Directory('C:\expd20\source\dclipx\*.*')
bEval := {|a|a[F_NAME] := Upper(a[F_NAME])}
DC_AEval( aDir, bEval,,,.t., )
bEval := {|a|Qout(Pad(a[F_NAME],20)),QQout(a[2])}
bFor := {|a|a[F_SIZE] > 2000 }
bWhile := {|a|a[F_SIZE] < 200000 }
DC_AEval( aDir, bEval,,,, bFor, bWhile)
wait
RETURN nil
* ------------
FUNCTION DC_Aeval( aArray, bBlock, nStart, nCount, lAssign, bFor, bWhile )
LOCAL nLen := Len(aArray), i, n := 0
DEFAULT nStart := 1, ;
        nCount := nLen, ;
        lAssign := .f.
FOR i := nStart TO nLen
  IF n++ >= nCount
    EXIT
  ENDIF
  IF !Empty(bWhile) .AND. !Eval(bWhile,aArray[i])
    EXIT
  ENDIF
  IF Empty(bFor) .OR. Eval(bFor,aArray[i])
    IF lAssign
      Eval( bBlock, @aArray[i] )
    ELSE
      Eval( bBlock, aArray[i] )
    ENDIF
  ENDIF
NEXT
RETURN aArray
 
			
					
				Re: aEVAL
				Posted: Thu Oct 13, 2016 2:46 am
				by unixkd
				Thanks Roger
That is excellent. Will be a good addition to eXpress++ next release.
Joe