Gnuplot, check if a function exists (defined)

This document demonstrates how to check if a variable has previously been defined in the gnuplot script.

Example from the document:

a = 10
if (exists("a")) print "a is defined"
if (!exists("b")) print "b is not defined"

However, is it possible to check whether a function has been previously defined?

In other words, is there a way to do the following:

f(x) = 2*x 
if (exist("f(x)") print "Function is defined"

Thank!

+4
source share
1 answer

Each user-defined function is available as a special variable with a prefix GPFUN_:

f(x) = 2*x
show variables GPFUN

prints

Variables beginning with GPFUN:
        GPFUN_f = "f(x) = 2+x"

So you can check the function with

f(x) = 2*x 
if (exist("GPFUN_f") print "Function f is defined"
+3
source

Source: https://habr.com/ru/post/1652879/


All Articles