|
From: James R. V. Z. <jr...@co...> - 2009-01-29 03:31:58
|
Ethan A Merritt <merritt@u.washington.edu> writes:
>On Monday 26 January 2009, James R. Van Zandt wrote:
>>
>> I propose the patch below, which adds a function that returns the
>> string that defines a specified user defined function.
...
>A couple of thoughts:
>
>It is already possible to do essentially the same thing by reversing
>the order of operations and using the recently added evaluate() function:
>
> gnuplot> def = "f(x) = 1-x**2/2"
> gnuplot> evaluate(def)
> gnuplot> plot [-1:1] cos(x), f(x) title def
This seems awkward to me.
>Another possibility is to make the function definitions visible as
>string variables directly, exactly as the existing variables are.
>
> gnuplot> g(x,y) = x**2 + y**3
> gnuplot> show variable GPFUN
> Variables beginning with GPFUN:
> GPFUN_g = "g(x,y) = x**2 + y**3"
> gnuplot> set label GPFUN_g at graph .05, .95
I think this is about as handy as the definition() function.
It would even let us retire the "show functions" command.
It would be easy to create an associated string variable when
recording the definition of a function.
A diabolical user could goof this up:
gnuplot> g(x,y) = x**2 + y**3
gnuplot> GPFUN_g = 42
gnuplot> set label GPFUN_g at graph .05, .95
but I don't suppose that is worth worrying about.
The next step might be for the expression parser to look for functions
via the string variable. Probably not worth the trouble.
By the way, you slipped in a useful generalization of the "show
variables" command. I would extend it to allow globbing:
gnuplot> show variable xy*z
xyaz = 13
xybz = 14
xyzz = "forty two"
- Jim Van Zandt
|