On Fri, 9 Nov 2012, Sven Schreiber wrote:
Am 09.11.2012 15:30, schrieb Allin Cottrell:
> On Fri, 9 Nov 2012, Pindar wrote:
>> The function 'isscalar' seems to be broken (and is only named on p. 148
in
>> the Command Reference).
>
> Yes, it seems to be orphaned (and anyway does not seem to be
> very useful). Let's get rid of it.
I'm not saying I need it, but it isn't obvious to me why it is less
useful in principle than for example 'isstring()'. Instead it seems to
be a natural complement to the other 'is...()' functions, doesn't it?
Maybe I was too glib. But actually, it seems to me that all we
really need is isnull() -- though I wouldn't propose at this
point that we trash the other is*() functions that are
documented and working.
When/why do we need, e.g., isstring()? One possible use case
is simply that you've defined a bunch a variables and now
can't remember their types. But IMO that's kinda silly and not
worth supporting in itself. The real use case is for function
writers who have made certain arguments optional and want to
test whether the caller has supplied anything. Here's a
stylized example:
<hansl>
function void foo (string s[null], scalar *x[null])
if isstring(s)
printf "Got a string arg: %s\n", s
else
printf "s: arg is null\n"
endif
if isnull(x)
printf "x: arg is null\n"
else
printf "Got a scalar arg: %g\n", x
endif
end function
# invocation with no args
foo()
scalar p = 4
# invocation with args
foo("throgmorton", &p)
</hansl>
The only occasion on which isscalar() would be truly
informative would be as a counterpart to isstring in the
context above: to see if the caller passed a pointer to
scalar when there was the option of not doing so. And isnull()
does that job fine.
(Note that if a scalar parameter is not "pointerized" but has
a default value, using isscalar would not be informative since
it will return 1 regardless of whether the caller supplied a
value.)
But if I'm missing something, please let me know!
Allin