[Gretl-devel] Default value specification for scalar and integer arguments
cottrell at wfu.edu
Sat Jul 4 09:48:06 EDT 2015
On Sat, 4 Jul 2015, Sven Schreiber wrote:
> Am 04.07.2015 um 02:45 schrieb Allin Cottrell:
>> On Fri, 3 Jul 2015, Allin Cottrell wrote:
>>> On Fri, 3 Jul 2015, Sven Schreiber wrote:
>>> But in fact "int foo" seems to be taken as specifying a default of
>>> 0. Presumably this should be fixed; unless perhaps there are lots of
>>> scripts out there that rely on the undocumented and formally wrong
> Well I stumbled over this in one of Jack's functions in SVAR...
That's a good indication that the above should _not_ be "fixed",
since it seems to be de facto standard hansl.
>> * The min and max fields in scalar parameter definitions are now
>> respected, which I'm afraid has not been the case to date.
> Meaning the bounds weren't checked?
In general, no.
>> /* we take a single value with no colon as indicating a default */
>> This does seem to be implicitly at variance with the documentation. We
>> have to adjust either the parser or the documentation, but which way
>> should we jump?
>> Is it more common to want to specify a default value, regardless of min
>> and max, or to specify a minimum regardless of max and default?
>> I guess the former would have to be a lot more common than the latter to
>> justify our current practice.
> I actually do think (without proof) that specifying a default is more
> common, such that the parameter also becomes optional.
That's my guess too.
> Although of course it is also conceivable that somebody writing 
> intends to enforce a non-negative value, this would not actually have
> been possible with gretl's current behavior. So keeping the behavior and
> updating the documentation seems the best way to me.
OK, that's now done in CVS. Just to be clear, here's a script to
illustrate the status quo:
function void foo (int k)
# k has a default of zero
function void bar (int k[0::])
# k has a minimum of zero
# should succeed (arg optional)
# should succeed (no minimum)
# should fail (there's no default)
# should fail (out of bounds)
# should succeed
# should succeed
Related: I fixed in today's CVS a bug introduced yesterday in the
function arg bounds checker.
More information about the Gretl-devel