On Thu, 1 Feb 2024, Sven Schreiber wrote:
this is a bug that is probably triggered only in unusual
circumstances, but
it happened to me in a kind-of real world function development scenario:
<hansl>
function void serc (const series s) # the 'const' here is important
if exists(s)
print "to be"
else
eval typename(s)
print "or not to be"
endif
end function
open denmark
print "call 1"
serc(LRM)
print "call 2"
serc(const) # "const" is a series ID 0 in all datasets
# -> produces "null" and "or not to be", as if "s"
inside
# the function didn't exist
</hansl>
This behavior has been there "forever" (or more precisely, ever
since the "const" modifier for hansl function arguments has been
supported).
It's quite an interesting problem. When a series is given as a
function argument without the "const" modifier, gretl gives the
function a copy of the incoming series, under the name given by the
function parameter. But when the "const" flag is given, the series
in question is shifted from the function-execution level of the
caller to that of the callee, and is renamed using the parameter
name -- and then these changes are reverted when the function exits.
However, that treatment of the "const" modifier cannot work when the
series passed is the one named "const" (with ID number 0). That
series is supposed to be automatically available at all levels of
function execution, and renaming it would make in unavailable under
its proper name inside the function -- a real bug.
This issue hasn't been reported before, which is not surprising
since passing series 0 as an argument is in general pointless, since
it's already available everywhere and is of no interest other than
as the intercept in a regression. I think I see a way of making it
harmless but I need to do some more testing before I'm sure.
Allin