Skip to content


Script-Fu

This is a very brief tutorial on Script-Fu / Scheme. It neither claims to be complete nor to be very educative. :-) But it should help an interested GIMP user understand scripts and create own. You'll need a working GIMP (>= 1.0.0) and its Script-Fu console to try out the examples presented here.

1. Scheme basics

1.1 General

Scheme differs a lot from other programming / scripting languages such as C, Pascal, Perl etc. One of those differences is Scheme's statements' structure. Generally, as everything are lists:

( function parameters )

Every statement is enclosed in parenthesis and the first expression is the function to call, followed by its parameters (so-called "prefix notation").

1.2 Arithmetics

Arithmetical operators are computed via insertions into lists in Scheme. Several parameters and encapsulation are allowed:

(/ 7 4)
(+ 6 5 3)
(* 5 (+ 1 3))
(- a 8 b)

Important note: In Scheme, every operator has to be separated by whitespaces. E.g. you cannot write (+2 (/3 5)! This makes sense since the lists suddenly lacks an item.

1.3 Variables

Variables in Scheme haven't got any types. You don't have to worry about all the integers, strings etc.. :-) Variables are usually declared using the command let*. Here, a is declared and gets the value 7:

(let* ((a 7)))

Changing a variable's value is performed by set!:

(let* ((x 2)) (set! x (+ x 1)))
1.4 Lists

Lists in Scheme can be compared with arrays or structs in other languages. They allow you to store and access different values in one variable. Lists are returned by many built-in GIMP functions. This is how a literate list can be declared:

(let* ((d '(6 2 9 4))))
(let* ((d '("six" "two" 9 "four"))))

car lets you access the first element of a list:

(car '(4 1 0))

The rest of a list can be accessed by cdr:

(cdr '(4 1 0))
1.5 Functions

Functions are defined by define:

(define (divide a b) (/ a b))

Call this function like this:

(divide 2 7)
1.6 Appendix

If you want to learn more about Scheme, Script-Fu and its functions, have a look at the GIMP manual.