|
From: Daniel J S. <dan...@ie...> - 2006-08-13 23:18:40
|
Ethan A Merritt wrote:
> On Sunday 13 August 2006 01:47 pm, Petr Mikulik wrote:
>
>>gnuplot> print words(4)
>> internal error : non-STRING argument
>>gnuplot> print exists(4)
>>0
>>
>>Shouldn't we expect the same error message?
>>(and "internal error: ...", not "... error : ...")
>
>
> Maybe. I'm not sure.
> The important thing is the return value, not the error message.
>
> Consider the patch
> ###################################################################
> --- gnuplot/src/standard.c 2006-07-15 19:14:01.000000000 -0700
> +++ gnuplot-cvs/src/standard.c 2006-08-13 14:52:24.000000000 -0700
> @@ -989,6 +989,7 @@
> gpfree_string(&a);
> push(Ginteger(&a, udv->udv_undef ? 0 : 1));
> } else {
> + int_warn(NO_CARET,"internal error : non-string argument");
> push(Ginteger(&a, 0));
> }
> #endif
> ###################################################################
> With this patch in place, you now see
>
> gnuplot> print exists(foo)
> undefined variable: foo
> gnuplot> print exists(89)
> warning: internal error : non-string argument
> 0
> gnuplot> foo = 89
> gnuplot> print exists(foo)
> warning: internal error : non-string argument
> 0
>
> So with the patch it does print "non-string argument" as
> a warning. But should it return 0, or 1? At this point we
> do know that there was a variable "foo", even if the query
> contained a syntax error. It is complicated by the question
> of recursion:
>
> gnuplot> foo = "var"
> gnuplot> print exists(foo)
> 0
> gnuplot> var = 89
> gnuplot> print exists(foo)
> 1
>
> In this example foo is a defined variable, but is the lack
> of quotes an unintentional syntax error, or is it an intended
> indirect query? There is no way of knowing.
>
> Daniel Sebald wrote
>
>>Is this 4.2 critical, Ethan?
>>Otherwise, we can create a bug report and come back to it.
>
>
> But I don't actually think it's a bug.
> At worst you could call it a lack of an error message.
>
> But as the example above shows (and you gave a similar one)
> it is not always an error to pass an unquoted variable name.
> So although the error message is strictly speaking correct,
> it may still be confusing.
OK, I see your point. However, why is it necessary to have exists(#) return a value? Could the int_warn() be changed to int_error()?
(Attached is a patch, overblown containing an attempt to place all "internal error" messages under a set of defines. Toss it if you don't want that much.) The output is:
Terminal type set to 'x11'
gnuplot> print exists(foo)
undefined variable: foo
gnuplot> print exists(89)
internal error: STRING operator applied to non-STRING type
gnuplot> foo = 89
gnuplot> print exists(foo)
internal error: STRING operator applied to non-STRING type
gnuplot> foo = "var"
gnuplot> print exists(foo)
0
gnuplot> var = 89
gnuplot> print exists(foo)
1
|