A small novelty in git which may be of use to developers: you can
now use the "store" command, with a new --functions option, to save
function definitions as XML. Material saved in this way can then be
loaded using "include" on the XML file.
What's the point? The short story is that it should be a bit faster
to load functions from XML rather than "raw hansl", if you have a
set of several, possibly complicated, functions. And there's also a
potential benefit for anyone writing a C program which uses libgretl
independently of the gretl CLI and GUI clients.
Why faster? When gretl is handling a raw hansl function definition,
we run the full parser for hansl statements, and carry out a number
of checks (e.g. to see if there's a mismatch in the use of if, elif
and endif). But if a function definition has already been processed
into XML by libgretl (as happens with gfn packages) we assume it's
pre-checked, and can simply use libxml2 to zap the function into
memory.
What about the C angle? Up till now there has been no
straightforward way to load hansl functions in the context of a
"libgretl C program", but now you can do
<C>
int err;
err = load_XML_functions_file(<XML filename>, OPT_NONE, NULL);
</C>
and the functions will be pulled into memory.
Here's a little illustration of usage in gretl or gretlcli:
initial script:
<hansl>
function scalar trivial (scalar a)
return (a+3)^2
end function
store trivial.xml --functions
</hansl>
and later:
<hansl>
include trivial.xml
eval trivial(2)
</hansl>
An XML file produced in this way will contain all the functions that
are currently defined, other than those that belong to gfn packages
-- since there should already be an external XML representation of
the latter.
Allin
Show replies by date