Dear Allin,
Agreed!
But now I know my confusion comes from the null list argument. See the
following example. I did not check the optional argument.
function test2 (series y, int order[0:2:1], list option[null])
option
end function
And in the gretl console, I type:
? list myList=0
Replaced list myList
? test2(djclose,1,myList)
const
? test2(djclose,1)
null
That is, there is no error message.
But you are right, the function writer has to test it before trying to use it.
Thanks
Yi-Nung
2009/5/21 Allin Cottrell <cottrell(a)wfu.edu>:
On Thu, 21 May 2009, yinung at Gmail wrote:
> I tested the User-defined functions and found some potential errors.
> For example, my function is:
>
> <script>
> function test (series y, int order[0:2:1], string option[null])
> if option="nc"
> printf "%s\n","empty"
> else
> printf "%s\n","no options"
> end if
> end function
> </script>
>
> the argument, string option[null], above should indicate that the
> "option" string should be optional.
>
> After normally processing it as a package, I execute this function via
> GUI (the same via command line). If I choose the default "null" as
> automatically specified by gretl, I got an error:
>
> "The symbol 'otion' is undefined... error evaluating 'if'
"
I don't think there's any bug here. If the string argument to a
function may be given as null, then the function writer has to
test it before trying to use it:
function test (series y, int order[0:2:1], string option[null])
if isstring(option)
printf "option: got '%s'\n", option
else
print "no option given"
end if
end function
Allin Cottrell
_______________________________________________
Gretl-users mailing list
Gretl-users(a)lists.wfu.edu
http://lists.wfu.edu/mailman/listinfo/gretl-users