|
From: Daniel J S. <dan...@ie...> - 2006-08-14 06:20:17
|
Petr Mikulik wrote:
>> You are missing my point.
>> foo is a variable. It may hold a string ("xxx") or it may hold an
>> integer (9).
>> It is legal to call
>> if (exists(foo))
>> in the first case, and the return code is 1, which tells you that foo
>> contains
>> the name of a defined variable.
>>
>> As I see it, if foo = 9 then exists(foo) should return 0, which tells
>> you that
>> foo does _not_ contain the name of a defined variable. That is what
>> it does
>> now, and I think it is correct. Daniel's patch would have it error
>> out rather
>> than returning.
>
>
> Ok, you are right.
>
>>> gnuplot> help exists
>>> `exists("X")` returns 1 if a variable named X has been defined,
>>> otherwise it returns 0.
>>
>> ^^^^^^^^^^^^^^^^^^^^^^^
>>
>> That is exactly what I am saying. If the argument to exists() is not a
>> defined variable name (i.e. a string), then exists() should return 0.
>> Not error out; return 0.
>
>
> Could you perhaps add this into "help exists"?
More than that. Rephrase things to remove ambiguity. One can look at the above help and assume implicitly that X must be inside a string. How about:
`exists(ARG)` returns 1 if its argument is a string containing
a variable that has been defined, e.g., ARG="X" where X has
been defined. Otherwise the function returns 0.
THEN we must change this behavior
gnuplot> print exists()
^
invalid expression
gnuplot> print exists(empty)
undefined variable: empty
so that both return 0. That or change the help description to refine things even further:
`exists(ARG)` returns 1 if its argument is a string containing
a variable that has been defined, e.g., ARG="X" where X has
been defined. Otherwise the function returns 0 if ARG is a
valid expression and errors if ARG is not a valid expression.
Daniel
|