Allin Cottrell schrieb:
Up till now, the definition of a user-function in gretl has
been required to follow this pattern:
function <function-name> (<parameters>)
<function-body>
[ return <return-type> <variable-name> ]
end function
where <...> indicates a placeholder and [...] indicates an
optional element (functions are not required to return anything).
This has served us OK, but it's a bit clunky. Consider writing a
function to multiply a matrix by 2 (I know, pretty silly). The
most compact version would be something like:
function mtwo (matrix m)
x = 2 * m
return matrix x
end function
I've now relaxed the requirement that return lines must match the
pattern above. You can now do
return <expression>
The price you pay for this is that you have to specify the return
type as part of the first line of the definition:
function <return-type> <function-name> (<parameters>)
For example,
function matrix mtwo (matrix m)
return m * 2
end function
For a function that does not return anything you can write
function void <function-name> ...
The old-style syntax is still supported alongside the new.
Eventually we may want to mark it as deprecated and, after a
suitable lag, remove support.
well, that would break almost every script that contains a function,
right? IMHO that would frustrate too many gretl users too much, so
either the lag that we're talking about here should be in the order of
at least several years, or both styles should be continued to be
supported, at least internally.
I mean, now that 'return' accepts an expression, it wouldn't be too
difficult to also allow the old placement of the returned variable type,
would it?
(as in:
function mtwo (matrix m)
return matrix m * 2
end function
)
cheers,
sven