On Wed, 17 Oct 2018, Sven Schreiber wrote:
Am 15.10.2018 um 15:25 schrieb Riccardo (Jack) Lucchetti:
> the fact that we don't have named arguments for functions like R and Python
> have is sometimes a little inconvenient.
Thanks again for the initiative. Indeed it would be a major step for gretl /
hansl if something like keyword args (the Python jargon for that) were
possible.
>
> So I thought one could pass a string argument to a function with options of
> the kind "a = _something_", where _something_ is a scalar or a string, or
> better still, a sequence of these statements, separated by semicolons.
However, I'm afraid I don't like this string-wrapping approach. It obfuscates
things because the true nature of the arguments is not visible to gretl
anymore and the burden of checking and so forth is shifted to the hansl user
(both the package author and the end user).
> or perhaps into libgretl.
For such a fundamental thing I believe core gretl is the only way really.
Me too.
The question is how to achieve this without too much problems for
gretl (and
also for Allin, hehe). So I'm thinking of syntactic constructs that would be
unambiguous for the parser.
One wild idea would be a pair of square brackets to indicate that a keyword
is given. Example:
<hansl-future>
function void myfunc(int a)
print a
end function
# new optional call syntax:
myfunc([a = 5])
</hansl-future>
The idea is that a square bracket after an opening round bracket or a comma
would be illegal everywhere else (right?), so cannot be mistaken. Then inside
those square brackets it would be clear that it's not really an assignment,
but a named arg.
(One pre-requisite for this would be to finally ban the use of "=" as
standing in for "==", otherwise it's next to impossible I guess.)
On the other hand, maybe the "=" itself would already be enough to signal to
the parser that it's a name:
myfunc(a=5)
This of course is basically like it's done in Python (and other languages).
I reckon that's the best way to go: an identifier directly followed by
a single equals sign in an argument slot should be enough to designate
uniquely a named-parameter construct.
I'm not yet convinced this is worthwhile (I can see the benefit but
I'm not sure it outweighs the cost), but I'm willing to be persuaded.
Allin