On Fri, 26 Oct 2018, Sven Schreiber wrote:
> Am 26.10.2018 um 14:46 schrieb Allin Cottrell:
>> On Fri, 26 Oct 2018, Sven Schreiber wrote:
>>> 
>>> I don't mean to imply any consequences (except perhaps warnings and hints 
>>> to package writers in the docs), but for completeness it should perhaps be 
>>> noted that this is not entirely true: If you receive a list argument and 
>>> pick out certain series their names come from the outside.
>> 
>> But they cannot be referenced by their outer names within the function, you 
>> have to use the List.$i syntax. Here's an example:
>> 
>> <hansl>
>> function void argnames (list L)
>>   loop foreach i L
>>     series x$i = L.$i(-1)
>>     print x$i
>>   endloop
>> end function
>> 
>> open denmark
>> rename LRY sin # try to cause trouble!
>> list X = LRM sin
>> argnames(X)
>> </hansl>
>> 
>> Inside argnames() we're able to take a lag of the series known as "sin" in 
>> main without a problem.
> Also good to know, but what I meant is something like this:
>
> <hansl>
> clear
> function list LRM(int i)
>   print "just to have a function with this name"
>   list L1 = null
>   return L1
> end function
>
> function list exlag(list L)
>   s = varnames(L)[1]
>   series @s = L[1]
>   list out = @s(-1)
>   return out
> end function
>
> open denmark
> list Lo = exlag(LRM)
> list Lo print
> </hansl>
>
> Again, I'm not saying these artificial cases have to be caught, 
> just adding this example for completeness.
OK. But I'd say that what now happens with your example in git is 
correct. Within exlag(), the user-function LRM() is masked by the 
series-name LRM; the function is ignored and the first lag of LRM is 
created.
If that's not what "you" (hypothetical function-writer) wanted, then 
don't use varnames() on series you got via a list; you can't be sure 
that these names won't collide with other stuff -- not only 
functions, but variables of type other than series that you have 
defined. That's the point of the "List.$i" syntax.
I guess if we wanted to get very nanny-ish about this we could 
figure out a way to make varnames() fail on series whose names 
you're not supposed to have access to inside a function.
Allin
_______________________________________________
Gretl-devel mailing list
Gretl-devel@lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-devel