gnuplot

Appeared in:
1986
Paradigm:
Typing discipline:
File extensions:
.gp
Versions and implementations (Collapse all | Expand all):
Programming language

gnuplot is a command-driven interactive function plotting program. gnuplot isn’t a programming language in strict sense but it has decent scripting capabilities to write fairly complex programs.

Elements of syntax:

Inline comments #
Variable assignment variable = value
Comparison < > <= >=
If - then if (condition) ...

Examples:

Factorial:

Example for versions gnuplot 4.2.2

This example consists of two files: factorial.gp and run.gp to emulate loop through use of load, reread and if. Built-in factorial operator ! is used. Since return of ! operator has type real, function gprintf is used to remove trailing zeros after decimal point and decimal point itself.

### factorial.gp
print a, '! = ', gprintf("%.0f", a!)
a = a + 1
if (a <= 16) reread

### run.gp
#!/usr/bin/env gnuplot
a = 0
load "factorial.gp"

Hello, World!:

Example for versions gnuplot 4.2.2
#!/usr/bin/env gnuplot
print 'Hello, World!'

Fibonacci numbers:

Example for versions gnuplot 4.2.2

gnuplot provides no loops, and printing each number with a separate print command makes it appear on separate line, so a string variable res is used to accumulate the calculated numbers for printing after “looping”.

### run.gp
#!/usr/bin/env gnuplot
i = 1
a = 1
b = 1
res = ''
load "fibonacci.gp"
print res, '...'

### fibonacci.gp
res = res . a . ', '
c = a
a = b
b = b+c
i = i+1
if (i <= 16) reread