Hi,

I've noticed that in a lot of hansl code many lines are spent on copying stuff into bundles, and I wonder if that could be made easier. What I have in mind is something like the function below, which would be called for example like this:

copy2bundle(b, defbundle("m", mymatrix, "s", mystring, "m2", anothermatrix))

However, perhaps a built-in gretl function would be better and less clumsy. For example, the input wouldn't have to be wrapped in a transitory bundle and still the number of arguments to copy would be flexible.

(BTW: 'getkeys' is not syntax-colored.)

Opinions, endorsements?

Thanks,

sven

-----

<hansl>

function void copy2bundle(bundle *btarget, bundle bin)
 
  n = nelem(btarget)
  strings oldkeys = getkeys(btarget)
 
  # easy approach first:
  btarget = btarget + bin
 
  # check if we missed something
  if nelem(btarget) != n + nelem(bin)
    # need to go into detail
    matrix match = {}
    strings inkeys = getkeys(bin)
    loop i=1..nelem(inkeys) -q
      loop j=1..nelem(oldkeys) -q
        if inkeys[i] = oldkeys[j]
          match |= i
          break
        endif
      endloop
    endloop
    # process what we found (copy with overwrite)
    loop k=1..nelem(match) -q
      string s = inkeys[match[k]]
      btarget["@s"] = bin["@s"]
    endloop
  endif
endloop

</hansl>