[Gretl-devel] members of lists returned from functions

Allin Cottrell cottrell at wfu.edu
Sun Feb 10 11:04:30 EST 2008


On Sat, 9 Feb 2008, Sven Schreiber wrote:

> The example script below prints two identical series under the 
> name of "s1", which is "obviously" wrong...

Ah, there's a loose end here, in terms of behavior when a function 
returns a list: what should happen if the list contains 
one or more variables that have the same name as a variable that 
already exists at the caller level?  

What's happening at present can be exposed by this variant on 
Sven's script:

function test(void)
  series s1 = randgen(u,0,1)
  series s2 = randgen(u,2,3)
  list myl = s1 s2
  print "in test"
  print s1 -o
  return list myl
end function

nulldata 4
loop 2
  list check = test()
  varlist
  print "in caller"
  print s1 -o
end loop

The last "varlist" produces:

Listing 6 variables:
  0) const    1) index    2) s1       3) s2       4) s1     
  5) s2     

which is not nice.  It seems to me the second iteration should 
overwrite s1 and s2 -- agreed?

Allin.


More information about the Gretl-devel mailing list