Does HB_ExecFromArray work with multiple arrays?

247 views
Skip to first unread message

HBQuerier

unread,
Jun 30, 2020, 5:44:24 PM6/30/20
to Harbour Users
Hi,


Can you include several arrays in the place of aParams?  I want to execute a function that uses the Nth item from several arrays.

Like so:


cFuncName( Item_01_s, Item_02_s, Item_03_s )


HB_ExecFromArray
( cFuncName, [ Items_01_a, Items_02_a, Items_03_a ] )






iorp...@gmail.com

unread,
Jun 30, 2020, 6:25:22 PM6/30/20
to Harbour Users
if you use square brackets it is a string, for an array you must use curly brackets.

HBQuerier

unread,
Jun 30, 2020, 9:52:09 PM6/30/20
to Harbour Users
Of course I know it's curly brackets.  I was just repeating the format from the documentation.

What you pointed to, is different from the documentation.

Your link says

hb_ExecFromArray( <cFuncName> [, <aParams> ] )

, which seems to imply multiple arrays.


But the documentation (the Harbour doc from Minigui) says


HB_ExecFromArray( cFuncName, [ aParams ] ) --> result

, which seems to imply a single optional array parameter.


So, I guess the answer is to just try it, and see what happens.

Thanks & Regards,

DC

Seth Hovestol

unread,
Jul 1, 2020, 8:56:15 AM7/1/20
to Harbour Users
I wrote this for this purpose:

//returns array
// map( <xFunc, [,aArg1] [, aArgN])
function aMap(...)
  local aOut := {}
  local aTemp
   local aArgs := hb_aParams()
  local nArgCount := len(aArgs) // func is the first arg so skip it.
   local xFunc := iif(len(aArgs)>0,aArgs[1],nil)
  local nArgInd
  local lObject := hb_isObject(xFunc)
  local nArgStart := iif(lObject,3,2)
  local nResCount := iif(nArgCount>1,len(aArgs[2]),0)
  local nResInd
  local oObj := iif(lObject,xFunc,nil)
  if lObject
     xFunc := aArgs[2]
  endif
  for nResInd:=1 to nResCount
     aTemp := {}
     for nArgInd:=nArgStart to nArgCount
        aAdd(aTemp,aArgs[nArgInd][nResInd])
     next
     if lObject
        aAdd(aOut, HB_ExecFromArray(oObj,xFunc,aTemp))
     else
        aAdd(aOut, HB_ExecFromArray(xFunc,aTemp))
     endif
  next
return aOut

HBQuerier

unread,
Jul 21, 2020, 3:16:59 PM7/21/20
to Harbour Users
Holy sht.  I was nearly certain, that nobody would understand what I was asking about.

Thanks, Seth.  This is exactly what I needed.  I tested, and it works perfectly.

Seth Hovestol

unread,
Jul 21, 2020, 3:27:06 PM7/21/20
to Harbour Users
You may also want these, if you're looking for a more functional style:

// returns same type as cInitial calculated from each item
function aReduce(xFunc,aIn,xInitial)
   local nStart := 1
   local nLength := len(aIn)
   local nInd
   if hb_isNil(xInitial) .and. nLength>0
      nStart := 2
      xInitial := aIn[1]
   endif
   for nInd := nStart to nLength
      xInitial := HB_ExecFromArray(xFunc,{xInitial,aIn[nInd]})
   next
return xInitial

function aFilter(xFunc,aIn)
   local aOut := {}
   local nLength := len(aIn)
   local nInd
   
   for nInd := 1 to nLength
      if HB_ExecFromArray(xFunc,{aIn[nInd]})
         aAdd(aOut,aIn[nInd])
      endif
   next
return aOut

Vlad

unread,
Jul 21, 2020, 4:46:26 PM7/21/20
to Harbour Users
Thanks !!

HBQuerier

unread,
Oct 28, 2020, 7:18:13 PM10/28/20
to Harbour Users
Whoa.  I missed this one, months ago.  Thanks for taking the time to write and share this.

HBQuerier

unread,
Nov 17, 2021, 6:26:46 PM11/17/21
to Harbour Users
This has been of enormous value.  Thanks once again for sharing the code.

On Tuesday, July 21, 2020 at 3:27:06 PM UTC-4 shoves...@gmail.com wrote:
Reply all
Reply to author
Forward
0 new messages